SQL DELETE statement
The SQL DELETE statement is used to delete one or more rows in a table. The syntax of this statement is:
DELETE FROM table_name WHERE some_column=’some-value’;
We will use the following table named Employees:
+----------------+-----------+-----------+-----------+---------------------------------
| employeeNumber | lastName | firstName | extension | email
+----------------+-----------+-----------+-----------+---------------------------------
| 0 | Doe | John | x233333 | john@email.com
| 1002 | Murphy | Diane | x5800 | dmurphy@classicmodelcars.com
| 1056 | Patterson | Mary | x4611 | mpatterso@classicmodelcars.com
| 1076 | Firrelli | Jeff | x9273 | jfirrelli@classicmodelcars.com
| 1088 | Patterson | William | x4871 | wpatterson@classicmodelcars.com
| 1102 | Bondur | Gerard | x5408 | gbondur@classicmodelcars.com
| 1143 | Bow | Anthony | x5428 | abow@classicmodelcars.com
| 1165 | Jennings | Leslie | x3291 | ljennings@classicmodelcars.com
| 1166 | Thompson | Leslie | x4065 | lthompson@classicmodelcars.com
| 1188 | Firrelli | Julie | x2173 | jfirrelli@classicmodelcars.com
| 1216 | Patterson | Steve | x4334 | spatterson@classicmodelcars.com
| 1286 | Tseng | Foon Yue | x2248 | ftseng@classicmodelcars.com
| 1323 | Vanauf | George | x4102 | gvanauf@classicmodelcars.com
| 1337 | Bondur | Loui | x6493 | lbondur@classicmodelcars.com
| 1370 | Hernandez | Gerard | x2028 | ghernande@classicmodelcars.com
| 1401 | Castillo | Pamela | x2759 | pcastillo@classicmodelcars.com
| 1501 | Bott | Larry | x2311 | lbott@classicmodelcars.com
| 1504 | Jones | Barry | x102 | bjones@classicmodelcars.com
| 1611 | Fixter | Andy | x101 | afixter@classicmodelcars.com
| 1612 | Marsh | Peter | x102 | pmarsh@classicmodelcars.com
| 1619 | King | Tom | x103 | tking@classicmodelcars.com
| 1621 | Nishi | Mami | x101 | mnishi@classicmodelcars.com
| 1625 | Kato | Yoshimi | x102 | ykato@classicmodelcars.com
| 1702 | Gerard | Martin | x2312 | mgerard@classicmodelcars.com
| 17777 | Doe | John | x233333 | john@email.com
+----------------+-----------+-----------+-----------+---------------------------------
Suppose that John Doe has been fired and we need to delete his data from the table above.The following command performs can be used:
DELETE FROM employees WHERE firstName=’John’ AND lastName=’Doe’;
This would produce the following result:
+----------------+-----------+-----------+-----------+---------------------------------+
| employeeNumber | lastName | firstName | extension | email |
+----------------+-----------+-----------+-----------+---------------------------------+
| 1002 | Murphy | Diane | x5800 | dmurphy@classicmodelcars.com |
| 1056 | Patterson | Mary | x4611 | mpatterso@classicmodelcars.com |
| 1076 | Firrelli | Jeff | x9273 | jfirrelli@classicmodelcars.com |
| 1088 | Patterson | William | x4871 | wpatterson@classicmodelcars.com |
| 1102 | Bondur | Gerard | x5408 | gbondur@classicmodelcars.com |
| 1143 | Bow | Anthony | x5428 | abow@classicmodelcars.com |
| 1165 | Jennings | Leslie | x3291 | ljennings@classicmodelcars.com |
| 1166 | Thompson | Leslie | x4065 | lthompson@classicmodelcars.com |
| 1188 | Firrelli | Julie | x2173 | jfirrelli@classicmodelcars.com |
| 1216 | Patterson | Steve | x4334 | spatterson@classicmodelcars.com |
| 1286 | Tseng | Foon Yue | x2248 | ftseng@classicmodelcars.com |
| 1323 | Vanauf | George | x4102 | gvanauf@classicmodelcars.com |
| 1337 | Bondur | Loui | x6493 | lbondur@classicmodelcars.com |
| 1370 | Hernandez | Gerard | x2028 | ghernande@classicmodelcars.com |
| 1401 | Castillo | Pamela | x2759 | pcastillo@classicmodelcars.com |
| 1501 | Bott | Larry | x2311 | lbott@classicmodelcars.com |
| 1504 | Jones | Barry | x102 | bjones@classicmodelcars.com |
| 1611 | Fixter | Andy | x101 | afixter@classicmodelcars.com |
| 1612 | Marsh | Peter | x102 | pmarsh@classicmodelcars.com |
| 1619 | King | Tom | x103 | tking@classicmodelcars.com |
| 1621 | Nishi | Mami | x101 | mnishi@classicmodelcars.com |
| 1625 | Kato | Yoshimi | x102 | ykato@classicmodelcars.com |
| 1702 | Gerard | Martin | x2312 | mgerard@classicmodelcars.com |
+----------------+-----------+-----------+-----------+---------------------------------+