Bird
0
0

Identify the error in this SQL query:

medium📝 Debug Q14 of 15
SQL - LEFT and RIGHT JOIN
Identify the error in this SQL query:
SELECT a.id, b.value FROM A a LEFT JOIN B b ON a.id = b.id WHERE b.value > 10;
AThe ON clause is missing a join condition
BThe SELECT clause must include all columns from both tables
CLEFT JOIN should be INNER JOIN for this query
DThe WHERE clause filters out rows where b.value is NULL, negating LEFT JOIN effect
Step-by-Step Solution
Solution:
  1. Step 1: Understand LEFT JOIN with WHERE filter

    The WHERE clause filters rows after join. Filtering on b.value > 10 excludes rows where b.value is NULL.
  2. Step 2: Effect on LEFT JOIN

    This filtering removes rows without matches in B, making LEFT JOIN behave like INNER JOIN.
  3. Final Answer:

    The WHERE clause filters out rows where b.value is NULL, negating LEFT JOIN effect -> Option D
  4. Quick Check:

    Filtering on right table in WHERE breaks LEFT JOIN [OK]
Quick Trick: Use ON for right table filters, not WHERE, to keep LEFT JOIN effect [OK]
Common Mistakes:
MISTAKES
  • Filtering right table columns in WHERE after LEFT JOIN
  • Confusing ON and WHERE clauses
  • Assuming LEFT JOIN always keeps all left rows regardless of WHERE

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes