π§ Quick Syntax:
DELETE FROM table_name
WHERE some_condition;
Basically:
βHey SQL, go to this table, and delete the rows that match this condition.β
β οΈ Warning First
NEVER run DELETE
without WHERE
Unless you really want to delete everything π¬
DELETE FROM friends; -- deletes ALL rows!
π§Ύ Current friends
table:
id |
name |
age |
phone |
1 | Olivia | 26 | 5550001234 |
2 | Mason | 24 | 5556712345 |
3 | Zoe | 30 | 5559083344 |
4 | Ethan | 21 | 5554421199 |
5 | Harper | 25 | 5552223344 |
β
Example 1: Delete Ethan from the table
DELETE FROM friends
WHERE name = 'Ethan';
π‘ Output:
Query OK, 1 row affected
Table Now:
id |
name |
age |
phone |
1 | Olivia | 26 | 5550001234 |
2 | Mason | 24 | 5556712345 |
3 | Zoe | 30 | 5559083344 |
5 | Harper | 25 | 5552223344 |
β
Example 2: Delete everyone older than 28
DELETE FROM friends
WHERE age > 28;
π‘ Output:
Query OK, 1 row affected
Table Now:
id |
name |
age |
phone |
1 | Olivia | 26 | 5550001234 |
2 | Mason | 24 | 5556712345 |
5 | Harper | 25 | 5552223344 |
π§ Recap
DELETE FROM table WHERE condition
removes specific rows
- NEVER forget the
WHERE
unless you’re okay deleting everything
- It’s permanent β no undo unless youβve got backups