Joining Tables
Real data is split across tables to avoid repetition: a customers table and an orders table that references it by id. To answer "who ordered what" you JOIN them on the matching column:
SELECT customers.name, orders.item
FROM orders
JOIN customers ON customers.id = orders.customer_id;An INNER JOIN (the default JOIN) keeps only rows that match on both sides. This is the single most important SQL skill for real applications.
Write orders_with_names(con) returning a list of (customer_name, item) tuples by joining orders to customers on the customer id, ordered by the order id. Press Run.
Write orders_with_names(con) that JOINs orders to customers on customers.id = orders.customer_id and returns a list of (customer_name, item) tuples, ordered by orders.id.
This lesson is locked
Lessons open one at a time. Finish the previous lesson to unlock this one.