This SQLite post explains how to use the SQLite DELETE statement with syntax and examples.
The SQLite DELETE statement is used to delete a single record or multiple records from a table in SQLite.
The syntax for the DELETE statement in SQLite is:
The table that you wish to delete records from.
Optional. The conditions that must be met for the records to be deleted. If no conditions are provided, then all of the records in the table will be deleted.
Let's look at a simple SQLite DELETE query example, where we just have one condition in the DELETE statement.
For example:
This SQLite DELETE example would delete all records from the employees table where the last_name is 'Smith'.
You may wish to check for the number of rows that will be deleted. You can determine the number of rows that will be deleted by running the following SQLite SELECT statement before performing the delete.
Let's look at a SQLite DELETE example, where we just have two conditions in the DELETE statement.
For example:
This SQLite DELETE example would delete all records from the employees table where the last_name is 'Smith' and the employee_id is less than 50.
You may wish to check for the number of rows that will be deleted. You can determine the number of rows that will be deleted by running the following SQLite SELECT statement before performing the delete.
You can also perform more complicated deletes.
You may wish to delete records in one table based on values in another table. Since you can't list more than one table in the SQLite FROM clause when you are performing a delete, you can use the SQLite EXISTS clause.
For example:
This SQLite DELETE example would delete all records in the employees table where there is a record in the positions table based on the position_id field.
You may wish to check for the number of rows that will be deleted. You can determine the number of rows that will be deleted byrunning the following SQLite SELECT statement before performing the delete.