Bird
0
0

Consider this SQL query:

medium📝 Debug Q14 of 15
SQL - LEFT and RIGHT JOIN
Consider this SQL query:
SELECT a.id, b.value FROM A a LEFT JOIN B b ON a.id = b.a_id WHERE b.value > 10;

Why might this query return fewer rows than table A has?
ABecause the query syntax is invalid and causes an error.
BBecause LEFT JOIN only returns rows with matching b.value > 10.
CBecause the WHERE clause filters out rows where b.value is NULL, removing unmatched rows.
DBecause the ON condition is incorrect and causes no matches.
Step-by-Step Solution
Solution:
  1. Step 1: Understand LEFT JOIN with WHERE filter

    LEFT JOIN keeps all rows from A, but WHERE filters after join.
  2. Step 2: Effect of WHERE on NULLs from unmatched rows

    Rows with no match have b.value as NULL, and WHERE b.value > 10 excludes NULLs, removing those rows.
  3. Final Answer:

    Because the WHERE clause filters out rows where b.value is NULL, removing unmatched rows. -> Option C
  4. Quick Check:

    WHERE filters NULLs after LEFT JOIN, reducing rows [OK]
Quick Trick: WHERE on right table column after LEFT JOIN filters out NULLs [OK]
Common Mistakes:
MISTAKES
  • Thinking LEFT JOIN always keeps all left rows regardless of WHERE
  • Confusing ON and WHERE filtering effects
  • Assuming query syntax error causes fewer rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes