SQL Café · Lesson 1 of 8

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:

You say to the waiter “Please bring me the item and the price from the menu, only things under £4.”
↓ same thing in SQL
SELECT item, price FROM menu WHERE price < 4;
The one thing to remember

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.

SELECT What do you want to see? Picks columns ↕ (top to bottom)

Name the columns you want, like item, price. A star * means “everything”.

FROM Where is it? Picks the table

Tell it which table to open. Today we only have one: menu.

WHERE Which ones? Picks rows ↔ (left to right)

A test every row must pass, like price < 4. It's optional. Leave it out to keep every row.

Fun fact that helps it stick: you write the words in the order of the three questions, but the database does them in a different order. It opens the table first, throws away rows second, and picks columns last. You'll see this happen in the playground below.
You write:SELECT→FROM→WHERE It runs:FROM→WHERE→SELECT
Read the code one word at a time

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 it out loud
Every symbol, explained

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.

WriteSay it asExampleWhy it's there
The three main words
SELECT“Please show me…”SELECT itemAlways first. Says which columns you want to see.
FROM“…from the…”FROM menuSays which table to look in.
WHERE“…but only where…”WHERE price < 4Optional. A test that each row must pass to stay.
Punctuation
,“and”item, priceSeparates 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 < 4Memory trick: the small pointy end faces the smaller side. 3 < 4.
>“is more than”calories > 200The wide open mouth faces the bigger side. 5 > 4.
<=  >=“at most” / “at least”price <= 4Same as < and >, but the number itself also counts. £4.00 passes price <= 4.
Joining two tests
AND“and also”type = 'food' AND price < 5Both tests must be true. Makes the answer smaller.
OR“or”type = 'drink' OR price < 4Either test can be true. Makes the answer bigger.
Two things that don't matter: capital letters and line breaks. 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.
Your turn

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.

Mission

Ctrl + Enter also runs
Or try one of these
  1. 1
  2. 2
  3. 3

Notice the order: FROM happens first and SELECT happens last, even though you wrote SELECT first.

Lock it in

Five quick questions

Answering from memory is the fastest way to make something stick. Wrong answers explain themselves, so please don't worry.

Take this with you

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) or OR (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.