×

sql · level 2 · unit 3 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Add one JOIN for every extra table you need.

Customers and dishes have a link: one customer can order many dishes, and one dish can be ordered by many customers. The orders table sits in the middle, with a foreign key to each.

To see who ordered what, start from orders and add a JOIN for each table it points at. Every JOIN has its own ON.

Once all three are joined, you can do maths across them, like d.price * o.quantity for the cost of each order.

SELECT c.name, d.dish, o.quantity
FROM orders o
JOIN customers c ON o.customer_id = c.id
JOIN dishes d ON o.dish_id = d.id
ORDER BY o.id;

Forget an ON and every row pairs with every row of that table.