SQL DELETE statement

DELETE statement

To delete all the data from the table but not the table itself, use a query with a DELETE FROM statement.

For example, let's delete all the information from the following table titled books:

To do that with the query will be:

DELETE FROM books;

As a result of the query execution, the table books is empty now.

Delete selected rows

Use DELETE FROM statement to delete only selected rows from a table.

For example, let's delete some information from the following table titled books:

Some books from the table are unavailable (their quantity equals zero). To delete records about these books, the query with a WHERE clause will be:

DELETE FROM books 
WHERE quantity = 0;

This query will delete all the rows from the table books where the logical expression

quantity = 0

is true.

After the execution of the query, the books table will look like this:

Written by

Master SQL by choosing your ideal learning course

View all courses

Create a free account to access the full topic

Sign up with Google
Sign up with Google
Sign up with JetBrains
Sign up with JetBrains
Sign up with Github
Sign up with GitHub
Coding thrill starts at Hyperskill
I've been using Hyperskill for five days now, and I absolutely love it compared to other platforms. The hands-on approach, where you learn by doing and solving problems, really accelerates the learning process.
Aryan Patil
Reviewed us on