Bird
0
0

Consider this query:

medium📝 Debug Q14 of 15
SQL - LEFT and RIGHT JOIN
Consider this query:

SELECT a.id, b.value FROM A LEFT JOIN B ON a.id = b.a_id WHERE b.value > 10;

What is the problem with this query if you want to keep all rows from A?
AThe WHERE clause filters out rows where b.value is NULL, losing some left rows.
BThe ON clause is missing a join condition.
CLEFT JOIN should be replaced with INNER JOIN for correct results.
DThe SELECT statement is missing table aliases.
Step-by-Step Solution
Solution:
  1. Step 1: Understand effect of WHERE on LEFT JOIN

    WHERE filters after join, so rows with NULL b.value are removed, losing left rows.
  2. Step 2: Identify how to fix to keep all left rows

    Move condition to ON clause or use WHERE b.value > 10 OR b.value IS NULL to preserve unmatched rows.
  3. Final Answer:

    The WHERE clause filters out rows where b.value is NULL, losing some left rows. -> Option A
  4. Quick Check:

    WHERE after LEFT JOIN can remove unmatched rows [OK]
Quick Trick: Put filters on right table in ON, not WHERE, to keep all left rows [OK]
Common Mistakes:
MISTAKES
  • Assuming WHERE doesn't affect LEFT JOIN results
  • Confusing ON and WHERE clauses
  • Replacing LEFT JOIN with INNER JOIN unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes