Count deleted records after a DELETE Count deleted records after a DELETE sqlite sqlite

Count deleted records after a DELETE


After some digging, I figured out... after

DELETE FROM BOXES WHERE product='25043620' AND Order='0846'

I ask database for changes with:

SELECT changes()

and I get how many rows was deleted.


I don't think that you can combine the count and the delete. Do them individually.

Here's and example :-

Example - Using SQL EXISTS Clause

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 SQL FROM clause when you are performing a delete, you can use the SQL EXISTS clause.

For example:

DELETE FROM suppliersWHERE EXISTS  ( SELECT customers.customer_name    FROM customers    WHERE customers.customer_id = suppliers.supplier_id    AND customers.customer_name = 'IBM' );

This SQL DELETE example would delete all records in the suppliers table where there is a record in the customers table whose name is IBM, and the customer_id is the same as the supplier_id.

If you wish to determine the number of rows that will be deleted, you can run the following SQL SELECT statement before performing the delete.

SELECT COUNT(*) FROM suppliersWHERE EXISTS  ( SELECT customers.customer_name    FROM customers    WHERE customers.customer_id = suppliers.supplier_id    AND customers.customer_name = 'IBM' );

This from SQL: DELETE Statement


You could try putting the statement into a loop with the argument as the loops condition and then just let the loop count for you as it increments.