Bird
0
0

Find the mistake in this query to get unmatched orders:

medium📝 Debug Q7 of 15
SQL - LEFT and RIGHT JOIN
Find the mistake in this query to get unmatched orders:
SELECT o.order_id FROM orders o LEFT JOIN customers c ON o.customer_id = c.id WHERE c.id IS NOT NULL;
AThe JOIN should be RIGHT JOIN
BThe ON condition is reversed
CThe WHERE clause should check c.id IS NULL to find unmatched orders
DNo mistake, query is correct
Step-by-Step Solution
Solution:
  1. Step 1: LEFT JOIN keeps all orders

    Orders matched with customers or NULL if no match.
  2. Step 2: Filter unmatched orders

    WHERE c.id IS NOT NULL filters matched orders; to find unmatched, use c.id IS NULL.
  3. Final Answer:

    The WHERE clause should check c.id IS NULL to find unmatched orders -> Option C
  4. Quick Check:

    Use NULL check on right table to find unmatched [OK]
Quick Trick: Use WHERE right_table.key IS NULL to find unmatched rows [OK]
Common Mistakes:
MISTAKES
  • Using IS NOT NULL instead of IS NULL
  • Confusing LEFT JOIN with RIGHT JOIN
  • Incorrect ON condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes