Let's see some examples of the SQL DELETE statement using a sample table called customers, which has four columns: id, name, email, and phone.
To delete a single row from the table, you can use the following statement:
DELETE FROM customers
WHERE id = 5;
This statement will delete the row where the id column has the value 5.
To delete multiple rows from the table, you can use a logical operator, such as AND, OR, or IN, to combine multiple conditions in the WHERE clause. For example, to delete the rows where the name column starts with A or B, you can use the following statement:
DELETE FROM customers
WHERE name LIKE 'A%' OR name LIKE 'B%';
This statement will delete the rows where the name column has a value that begins with either A or B.
To delete all the rows from the table, you can either omit the WHERE clause or use a condition that is always true, such as 1 = 1. For example, to delete all the rows from the customers table, you can use either of the following statements: DELETE FROM customers;
DELETE FROM customers
WHERE 1 = 1;
However, be very careful when using this option, as you will lose all the data from the table and you may not be able to recover it.