Expressing DELETE statements
Expressing DELETE statements in jOOQ can be done via the DSLContext.delete() and DSLContext.deleteFrom() API or via DSLContext.deleteQuery() and DSLContext.executeDelete(), respectively. While the first three methods receive an argument of the Table<R> type, the executeDelete()method is useful for deleting a record as TableRecord<?> or UpdatableRecord<?>. As you can see from the following example, delete() and deleteFrom() work exactly the same:
ctx.delete(SALE) .where(SALE.FISCAL_YEAR.eq(2003)) .execute(); ctx.deleteFrom(SALE) .where(SALE.FISCAL_YEAR.eq(2003)) .execute();
Both of these expressions render this SQL:
DELETE FROM `classicmodels`.`sale` WHERE `classicmodels`.`sale`.`fiscal_year` = ?
Combining DELETE and row value expressions is useful for deleting via subselects, as in the following example:
ctx.deleteFrom(CUSTOMERDETAIL) ...