DELETE query

The SQL DELETE query is used to delete the existing records from a database table. Using the WHERE clause you specify the condition to identify the records to be deleted. You can combine several number of conditions using AND or OR operators. Please refer here to know about WHERE clause syntax.

Delete statement examples:

SQL

executeStatement("DELETE FROM employees e WHERE e.age >= 60 AND e.gender = 'male'");

QueryDSL

deleteFrom(employees)
    .where(
employees.age.goe(60).and(employees.gender.eq("male")))
    .execute();

Deleting all records from the database table

To delete all the records from the table, use DELETE without any conditions:

SQL

executeStatement("DELETE FROM customers c");

QueryDSL

deleteFrom(customers)    
    .execute();