SQL · Level 2 Joins

SQL INNER JOIN

Put customer names next to their orders with JOIN ... ON, and see why a missing ON condition multiplies every row.

  • JOIN ... ON
  • Table aliases
  • Only matching rows are kept

JOIN ... ON combines rows of two tables that match on a key. Trap: forget or mistype the ON condition and every order pairs with every customer, a cross join that multiplies rows without any error.

SELECT o.id, c.name
FROM orders AS o
JOIN customers AS c ON c.id = o.customer_id;

Return the id, the customer's name and the total of every order over 50, ordered by order id. In the database below, order 10 belongs to Ana.

Sample data from the first test. The other tests use different rows, so write a query, not a list of answers.

customers 3 rows
idINTEGERnameTEXT
1Ana
2Bo
3Cy
orders 4 rows
idINTEGERcustomer_idINTEGERtotalREAL
10180.0
11220.0
12355.5
13151.0
solution.sql
Test Suites Pending
Output