SQL – Delete Statement Cheat Sheet

SQL Delete all rows

DELETE FROM customer;

 

SQL Delete selection of rows

DELETE FROM customer
WHERE zcode = 'E';

 

SQL Delete rows based on a substring of the field

DELETE FROM customer
WHERE substr(postcode, 1, 4)  =   'CF64';

 

SQL Delete rows based on existence in another table

DELETE FROM customer
WHERE cusnum IN (SELECT cusnum FROM custdel);

 

Delete rows based on relative record number (RRN)

DELETE FROM customer
WHERE RRN(customer) BETWEEN 4000 and 4010);