Using the DELETE Command

The basic DELETE syntax is

DELETE FROM table_name
[WHERE some_condition_is_true]
[LIMIT rows]

Notice there is no column specification in the DELETE command—when you use DELETE, the entire record is removed. You might recall the fiasco earlier in this chapter, regarding grapes in the fruit table, when updating a table without specifying a condition caused all records to be updated. You must be similarly careful when using DELETE.

Assuming the structure and data in a table called fruit:

						mysql> select * from fruit; +----+------------+--------+ | id | fruit_name | status | +----+------------+--------+ | 1 | apple | ripe | | 2 | pear | rotten | | 3 | banana | ripe | | 4 | grape | rotten | +----+------------+--------+ 4 ...

Get Sams Teach Yourself PHP, MySQL® and Apache All in One now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.