Bird
0
0

Consider this SQL query:

medium📝 Debug Q14 of 15
SQL - Advanced Joins
Consider this SQL query:
SELECT a.id, b.value FROM tableA a RIGHT JOIN tableB b ON a.id = b.a_id WHERE a.id > 10;

What is the main issue with this query?
ARIGHT JOIN syntax is incorrect; it should be LEFT JOIN
BThe WHERE clause filters out rows where a.id is NULL, negating the RIGHT JOIN effect
CThe ON condition is invalid because columns have different names
DThe query will cause a syntax error due to aliasing
Step-by-Step Solution
Solution:
  1. Step 1: Understand RIGHT JOIN with WHERE filter

    RIGHT JOIN returns all rows from tableB and matching from tableA. Rows with no match have NULL in a.id.
  2. Step 2: Effect of WHERE a.id > 10

    The WHERE clause excludes rows where a.id is NULL, removing unmatched rows from tableB, which defeats the purpose of RIGHT JOIN.
  3. Final Answer:

    The WHERE clause filters out rows where a.id is NULL, negating the RIGHT JOIN effect -> Option B
  4. Quick Check:

    Filtering NULLs after RIGHT JOIN removes unmatched rows [OK]
Quick Trick: Filter NULLs in JOIN condition, not WHERE, to keep unmatched rows [OK]
Common Mistakes:
MISTAKES
  • Thinking RIGHT JOIN syntax is wrong
  • Ignoring NULL filtering effect in WHERE
  • Assuming aliasing causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes