SQL is just ordering at a café.
You already know how to ask a waiter for something. SQL is the same sentence, written in a way a computer understands. Look how each part lines up:
Every query asks three questions
Learn these three questions and you know the heart of SQL. Each word has its own colour on this page, so your eyes learn it too.
Name the columns you want, like item, price. A star * means “everything”.
Tell it which table to open. Today we only have one: menu.
A test every row must pass, like price < 4. It's optional. Leave it out to keep every row.
Every piece has a meaning, even the comma
Code looks scary when it's a block of symbols. Read it one piece at a time and you'll see it is just an English sentence. Please press Next (or click any piece) and read the sentence grow underneath.
Say each symbol out loud
Each symbol has an everyday word you can say instead. When you read a query, swap each symbol for its word and the code turns into a normal sentence.
| Write | Say it as | Example | Why it's there |
|---|---|---|---|
| The three main words | |||
| SELECT | “Please show me…” | SELECT item | Always first. Says which columns you want to see. |
| FROM | “…from the…” | FROM menu | Says which table to look in. |
| WHERE | “…but only where…” | WHERE price < 4 | Optional. A test that each row must pass to stay. |
| Punctuation | |||
| , | “and” | item, price | Separates a list, just like “tea, milk, sugar”. Put it between names, never after the last one. |
| * | “everything” | SELECT * | A shortcut for “all the columns”, so you don't have to type them all. |
| ' ' | “the word…” | type = 'drink' | Quotes mean “this is text, not a column name”. Without them SQL looks for a column called drink. Numbers never need quotes. |
| ; | “Done.” | … < 4; | The full stop at the end of the sentence. It tells the database your question is finished. |
| Comparisons (used after WHERE) | |||
| = | “is” | type = 'food' | Exactly the same as. |
| != | “is not” | type != 'food' | The ! means “not”. You can also write <>. |
| < | “is less than” | price < 4 | Memory trick: the small pointy end faces the smaller side. 3 < 4. |
| > | “is more than” | calories > 200 | The wide open mouth faces the bigger side. 5 > 4. |
| <= >= | “at most” / “at least” | price <= 4 | Same as < and >, but the number itself also counts. £4.00 passes price <= 4. |
| Joining two tests | |||
| AND | “and also” | type = 'food' AND price < 5 | Both tests must be true. Makes the answer smaller. |
| OR | “or” | type = 'drink' OR price < 4 | Either test can be true. Makes the answer bigger. |
select item from menu works just as well. We write the main words in CAPITALS only so they stand out from the names, the same way this page gives them colours.Playground: watch your query work
Please type a query and press Run. The table acts out each step, so you can see exactly what each word does.
- 1
- 2
- 3
Notice the order: FROM happens first and SELECT happens last, even though you wrote SELECT first.
Five quick questions
Answering from memory is the fastest way to make something stick. Wrong answers explain themselves, so please don't worry.
Your pocket card
Please take a screenshot of this card. Read it once tomorrow and once next week, and it will stick.
SELECTWhat do you want to see? (columns ↕)FROMWhere is it? (the table)WHEREWhich ones? (rows ↔, optional),means “and”:item, price. Never after the last name.*means every column.;means “Done.” It ends the question.- Text goes in
'quotes'. Numbers don't:type = 'drink',price < 4. - Join tests with
AND(both must be true) orOR(either one). - Compare with
=!=<><=>=
SQL Café is a free course by MASSH AI. Want SQL or data training for your team? Please get in touch.