Contents /
Previous /
Next
Data Deletions: DELETE
Deletion is expressed in the same way as a SELECT query.
Instead of displaying, the selected tuples are removed from
the database (only whole tuples can be deleted).
DELETE FROM table WHERE condition
Tuples in table for which condition is true are deleted.
If the WHERE clause is omitted, all tuples are deleted.
One may only delete tuples from one relation at a time.
Example:
> SELECT * FROM friend;
firstname | lastname | age
-----------------+-----------------+-----
Mike | Nichols | 19
Cindy | Anderson | 23
Sam | Jackson | 22
Jim | Barnes | 25
(4 rows)
> DELETE FROM friend lastname = 'Barnes';
> DELETE FROM friend WHERE age > 22;