Bird
0
0

Identify the error in this SQL query using multiple LEFT JOINs:

medium📝 Debug Q14 of 15
SQL - LEFT and RIGHT JOIN
Identify the error in this SQL query using multiple LEFT JOINs:
SELECT a.id, b.name, c.status FROM tableA a LEFT JOIN tableB b ON a.id = b.a_id LEFT JOIN tableC c ON b.id = c.b_id WHERE c.status = 'active';
AThe SELECT clause must include all columns from joined tables
BThe JOIN conditions are missing ON clauses
CUsing LEFT JOIN twice is not allowed
DThe WHERE clause filters out rows where c.status is NULL, negating LEFT JOIN effect
Step-by-Step Solution
Solution:
  1. Step 1: Understand WHERE with LEFT JOIN

    The WHERE clause filters rows after JOINs. Filtering on c.status excludes rows where c is NULL, removing unmatched rows.
  2. Step 2: Effect on LEFT JOIN

    This makes the LEFT JOIN behave like INNER JOIN, losing rows from tableA without matching tableC rows.
  3. Final Answer:

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

    Filtering on joined table in WHERE breaks LEFT JOIN [OK]
Quick Trick: Use WHERE on main table only; filter joined tables in ON [OK]
Common Mistakes:
MISTAKES
  • Filtering joined table columns in WHERE instead of ON
  • Assuming multiple LEFT JOINs are invalid
  • Missing ON conditions causing cross joins

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes