SELECT … FROM gives you columns — but every row comes along. Real questions are about some rows: the engineers, the orders above €50, the customers in Ghent. WHERE is how you say which.
WHERE tests a condition against every row and keeps only the rows where it's true. One clause, and your query starts answering real questions.
See it before you write it
Filter the five employees to just the engineers, and three rows fall away:
| name | department | salary |
|---|---|---|
| Ada | Engineering | 62000 |
| Bo | Sales | 48000 |
| Cy | Engineering | 71000 |
| Di | Sales | 52000 |
| Eli | Marketing | 45000 |
WHERE department = 'Engineering'| name | department | salary |
|---|---|---|
| Ada | Engineering | 62000 |
| Cy | Engineering | 71000 |
Try it now — write the query the visual just showed: the name and salary of every employee in Engineering.
Your turn · Exercise
Write the query the visual showed: name and salary of every employee in the Engineering department.
The data
employees
5 rows returned
| name | department | salary |
|---|---|---|
| Ada | Engineering | 62,000 |
| Bo | Sales | 48,000 |
| Cy | Engineering | 71,000 |
| Di | Sales | 52,000 |
| Eli | Marketing | 45,000 |
Numbers compare without quotes
Conditions aren't just = on text. You have <, >, <=, >=, and <> (not equal). Run it, then change 50000 to 60000:
Watch out
The single biggest beginner trip-up: text goes in single quotes, numbers don't. WHERE department = Engineering (no quotes) makes the database look for a column named Engineering and errors. WHERE salary > '50000' quotes a number and invites subtle bugs. Text → quotes; numbers → bare.
Read it the way the database does
Even though you write SELECT first, the database thinks: FROM this table → WHERE these rows match → SELECT these columns. "Which table, which rows, which columns" is the order that makes queries easy to reason about — and it's exactly what the workspace's X-ray button shows you, stage by stage.
Your turn
Return the name and salary of every employee in the Sales department.
Your turn · Exercise
Return the name and salary of every employee in the Sales department.
The data
employees
5 rows returned
| name | department | salary | city |
|---|---|---|---|
| Ada | Engineering | 62,000 | Antwerp |
| Bo | Sales | 48,000 | Ghent |
| Cy | Engineering | 71,000 | Antwerp |
| Di | Sales | 52,000 | Bruges |
| Eli | Marketing | 45,000 | Ghent |
Which condition is written correctly?
Next: the rows are right — now put them in order.