Challenge - 5 Problems
LEFT JOIN Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find customers without orders
Given two tables, Customers and Orders, which query returns all customers who have never placed an order?
SQL
Customers(id, name) Orders(id, customer_id, order_date)
Attempts:
2 left
💡 Hint
Use LEFT JOIN to keep all customers and check for missing orders by filtering NULLs in the joined table.
✗ Incorrect
LEFT JOIN keeps all rows from Customers. If a customer has no matching order, the Orders columns are NULL. Filtering WHERE o.id IS NULL finds those customers without orders.
❓ query_result
intermediate2:00remaining
Identify products never sold
Which SQL query lists all products that have never been sold, given tables Products and Sales?
SQL
Products(product_id, product_name) Sales(sale_id, product_id, quantity)
Attempts:
2 left
💡 Hint
Use LEFT JOIN and check for NULL in the Sales table to find products without sales.
✗ Incorrect
LEFT JOIN keeps all products. If a product has no matching sale, s.sale_id is NULL. Filtering WHERE s.sale_id IS NULL returns products never sold.
📝 Syntax
advanced2:00remaining
Identify syntax error in LEFT JOIN query
Which option contains a syntax error when trying to find unmatched rows using LEFT JOIN?
SQL
Tables: Employees(emp_id, name), Projects(proj_id, emp_id)
Attempts:
2 left
💡 Hint
Check if the WHERE clause references a valid column or table alias.
✗ Incorrect
In option D, 'WHERE p IS NULL' is invalid because 'p' is a table alias, not a column. You must check a column like p.proj_id for NULL.
❓ optimization
advanced2:00remaining
Optimize query to find unmatched rows
Which query is the most efficient way to find customers without orders, assuming indexes on customer_id?
SQL
Customers(id, name) Orders(id, customer_id, order_date)
Attempts:
2 left
💡 Hint
NOT EXISTS often performs better than LEFT JOIN with NULL check for unmatched rows.
✗ Incorrect
Option C uses NOT EXISTS which can be optimized by the database engine using indexes efficiently. Option C works but may be slower. Option C can be slower and has issues with NULLs. Option C is incorrect logic.
🧠 Conceptual
expert2:00remaining
Understanding LEFT JOIN behavior with unmatched rows
What will be the output of this query?
Tables:
Authors(author_id, name)
Books(book_id, author_id, title)
Query:
SELECT a.name, b.title FROM Authors a LEFT JOIN Books b ON a.author_id = b.author_id WHERE b.book_id IS NULL;
Tables:
Authors(author_id, name)
Books(book_id, author_id, title)
Query:
SELECT a.name, b.title FROM Authors a LEFT JOIN Books b ON a.author_id = b.author_id WHERE b.book_id IS NULL;
SQL
Authors: 1, 'Alice' 2, 'Bob' 3, 'Carol' Books: 10, 1, 'Book A' 11, 1, 'Book B' 12, 3, 'Book C'
Attempts:
2 left
💡 Hint
LEFT JOIN keeps all authors. WHERE b.book_id IS NULL filters authors with no books.
✗ Incorrect
Bob (author_id 2) has no books in Books table, so LEFT JOIN produces NULL for b.book_id. The query returns Bob with title NULL.