
SQL practice
SQL JOIN practice questions
14 problems, ordered from easiest. They run in your browser, and 3 are free.
Start with Employee department namesThe idea in a minute
A join puts two tables side by side by matching a column. An INNER JOIN keeps only the rows that match on both sides. A LEFT JOIN keeps every row from the left table and fills NULL where nothing matched.
The mistakes are almost always about row counts: a join that repeats rows, or one that quietly drops them. The problems here ask you to check the count after a join as well as write it.
Example: Customers with and without orders
CREATE TABLE customers AS SELECT * FROM (VALUES (1,'Asha'),(2,'Ravi'),(3,'Meera')) t(customer_id, name);
CREATE TABLE orders AS SELECT * FROM (VALUES (10,1,450),(11,1,150),(12,2,300)) t(order_id, customer_id, amount);
SELECT c.name, COUNT(o.order_id) AS orders
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
GROUP BY c.name
ORDER BY c.nameWhat it prints
name orders
Asha 2
Meera 0
Ravi 1What to watch for
- Check how many rows you have before and after. A join on a column with repeats multiplies rows.
- A filter on the right table in WHERE can turn a LEFT JOIN into an INNER JOIN. Put that condition in ON instead.
- Use table aliases so it is clear which table each column comes from.
Joins problems
- Employee department namesbeginner · Free
- Employees with optional departmentbeginner · Free
- Customers who never orderedbeginner · Free
- Customers with more than 2 ordersintermediate · Locked
- Join row counts with duplicates and NULLsintermediate · Locked
- Fix a join that doubles revenueintermediate · Locked
- Salary grade from a band tableintermediate · Locked
- Usage by plan with point-in-time contractsadvanced · Locked
- First-touch attributionadvanced · Locked
- Last-touch attributionadvanced · Locked
- Cancellation rate excluding banned usersadvanced · Locked
- Source versus target reconciliationadvanced · Locked
- User purchase platformadvanced · Locked
- Advertiser status transitionsadvanced · Locked
Want a guided order across every topic? Open the practice sheets or the SQL hub.