SQL Kitchen

Lesson · Recipe № 001

SELECT

Lesson 1
Recipe

SELECT


A database table is just a spreadsheet. Every row is one thing, which for us is one dish, and every column is one fact about it. Everything on this card is pulling from the same dishes table:

name             station  price
Bifteki          grill    18
Baklava          pastry   7
Melitzanosalata  salad    16
Loukoumades      pastry   9
Souvlaki         grill    11
Dakos            salad    14

SELECT is how you ask for the columns you want, and FROM is how you say which table to pull them from. That's the whole idea. Everything else is just built on top of it.

Query

SELECT name FROM dishes;

↓ result

name
Bifteki
Baklava
Melitzanosalata
Loukoumades
Souvlaki
Dakos

If you want more than one column, you list them out with commas in between, and they come back in that same order.

Query

SELECT name, price FROM dishes;

↓ result

name             price
Bifteki          18
Baklava          7
Melitzanosalata  16
Loukoumades      9
Souvlaki         11
Dakos            14

And when you want every column, you don't have to type them all out. A * means all columns.

Query

SELECT * FROM dishes;

↓ result

You get the whole dishes table back, exactly like the one at the top of this card.

Rows come back in no particular order, and every result is itself a table. Every lesson after this one is really just you learning new ways to shape that table before it lands in front of you.

On the rail · tonight's orders

ORDER 001

for the specials board


The board out front is blank. Giorgos wants every dish we serve listed on it, just the names.

Your query returns

One row for each dish, showing only the name column.


ORDER 002

for table nine


Table nine keeps changing their mind. They want to see the whole menu with every detail on it.

Your query returns

Every dish, with all of its columns.


ORDER 003

for the prep list


Every station needs to know what it is cooking tonight. Giorgos wants each dish listed next to the station that makes it.

Your query returns

One row per dish, with the name first and the station second.