Given a table, you can select a subset of records.

Use the SELECT query combined with the WHERE clause to do that.

The WHERE clause will filter the records to those that match the condition.

You may like:
Learning SQL: Master SQL Fundamentals

WHERE clause

Example

You can select all records from a table using this query

1
SELECT * FROM table;

But what if you don’t want all records? You can select a specific record like this:

1
SELECT * FROM table WHERE id = 3;

Operators

This can work with any column from a table, e.g.

1
SELECT * FROM table WHERE age > 21;

You can combine this with other conditions:

1
SELECT * FROM table WHERE age > 21 AND age < 70;

Where to use

You can use the WHERE clause to filter results. The WHERE clause can be used not only on the SELECT query but also on the UPDATE and DELETE query.

Some quick examples to get the idea:

If you want to delete a record:

1
DELETE FROM table WHERE id=3;

To use with the update query:

1
UPDATE table SET column = 'value' WHERE ID = 2;

Video

Video tutorial of the WHERE clause