SQL Beginner Challenge 10: Find Missing Matches with LEFT JOIN + WHERE

Difficulty: Beginner
Estimated time: 15–20 minutes
SQL concepts: LEFT JOIN, WHERE ... IS NULL, finding missing relationships
Goal: Identify records that don’t have a matching row in a related table.

The Scenario

After building a report that includes all products (even those without suppliers), the product manager asks:

“Which products are missing a supplier?”

This is a classic real-world data quality question.

You’ll use:

  • a LEFT JOIN to keep all products, and
  • a WHERE filter to return only the rows where the supplier match is missing.

Database Tables

products

column_nametypedescription
product_idINTEGERUnique product ID
nameTEXTProduct name
categoryTEXTProduct category
priceDECIMALProduct price
supplier_idINTEGERReferences suppliers.supplier_id (can be NULL)

suppliers

column_nametypedescription
supplier_idINTEGERUnique supplier ID
supplier_nameTEXTSupplier name

Sample Data

products

product_idnamecategorypricesupplier_id
101Wireless MouseAccessories24.991
102Mechanical KeyboardAccessories89.001
10327-inch MonitorDisplays229.992
104USB-C HubAccessories34.50NULL
105Laptop StandWorkspace39.992
106WebcamAccessories59.9999

Notice: Product 106 has a supplier_id (99) that does not exist in suppliers.
That’s also considered “missing a supplier match.”

suppliers

supplier_idsupplier_name
1TechSource
2DisplayWorks

Your Task

Write a SQL query that returns:

  • Product name
  • supplier_id

…but only for products that do not have a matching supplier.

This includes:

  • Products where supplier_id is NULL
  • Products where supplier_id exists but does not match any supplier

Expected Output

namesupplier_id
USB-C HubNULL
Webcam99

Constraints

  • Use LEFT JOIN
  • Filter for missing matches using WHERE ... IS NULL
  • Do not use NOT IN for this challenge
  • Do not use SELECT *

Hint (Optional)

When a LEFT JOIN can’t find a match, the joined table’s columns become NULL.
That makes it easy to filter missing matches with:

  • WHERE s.supplier_id IS NULL

SELECT
p.name,
p.supplier_id
FROM products p
LEFT JOIN suppliers s
ON p.supplier_id = s.supplier_id
WHERE s.supplier_id IS NULL;

Explanation

  • LEFT JOIN keeps all products.
  • For products that don’t match a supplier, s.supplier_id becomes NULL.
  • WHERE s.supplier_id IS NULL filters the result to only “missing supplier” cases.

This pattern is widely used for:

  • Data quality checks
  • Detecting missing relationships
  • Finding orphan records

Common Mistakes

  1. Filtering on the wrong NULL
    • You want to check a column from the joined table (suppliers), not the left table.
  2. Using INNER JOIN
    • That would remove unmatched products before you can detect them.
  3. Using WHERE p.supplier_id IS NULL only
    • That would miss cases like supplier_id = 99 (invalid reference).

Optional Extension (Mini Bonus)

Try:

  1. Return missing suppliers only for Accessories.
  2. Sort missing items by product name.
  3. Add a computed flag:
    • CASE WHEN s.supplier_id IS NULL THEN 'Missing' ELSE 'OK' END

Next Challenge

If you want to keep going beyond Challenge #10, the next logical beginner topic is:

Beginner Challenge #11: Conditional Labels with CASE

🔗 View reference solution on GitHub
(After you’ve tried the challenge)

Want more practical SQL challenges?
Subscribe to the Solve With SQL newsletter and get new problems delivered to your inbox.