SQL JOIN practice exercises
SQL · Lesson 3
Ctrl/⌘ + Enter to run
✓
SQL Lesson 3 done.
You can join tables, keep the rows that don't match with LEFT JOIN, find what's missing, and spot the two traps that catch most people: WHERE after a LEFT JOIN and rows repeated by a join.
The 7 exercises in this lesson
- Orders only store a customer_id. Return each order's id together with the name of the customer who placed it.
- Return the customer name and amount of every order placed by a customer from TX.
- Return each customer's name and the total amount they've spent. Only customers with orders.
- Now every customer, even those who never ordered: return each name and their number of orders (0 if none).
- Who hasn't ordered yet? Return the names of customers with no orders.
- List every customer next to each Fern order they placed: the customer's name and the order's amount (its price), one row per Fern order. Customers without a Fern order still appear once, with an empty amount.
- Last one. How many different customers in each state have placed at least one order? Return the state and the number.