Loading lessons...
WHERE Clause
WHERE Clause
The WHERE clause filters records: it only keeps the rows that match a condition.
Basic example
SELECT * FROM Customers
WHERE Country = 'Mexico';
This returns only the customers whose Country is exactly 'Mexico'.
Text vs numbers
- Text:
WHERE City = 'Berlin' - Numbers:
WHERE CustomerID = 3 - Operators:
=,<,>,<=,>=,<>(not equal),!=
SELECT * FROM Products
WHERE Price > 30;
The full SELECT order
| Keyword | Purpose |
|---|---|
| SELECT | choose columns |
| FROM | choose table |
| WHERE | filter rows |
WHERE with a column you don't select
You can filter on a column that isn't in the result:
SELECT CustomerName FROM Customers
WHERE Country = 'Germany';
The result only shows names, but only German customers are included.
TL;DR
- WHERE filters rows based on a condition.
- Text needs quotes:
WHERE Country = 'Mexico'. - Comparison operators:
=,<>,>,<,>=,<=.