Bird
0
0

This query returns fewer rows than expected:

medium📝 Debug Q7 of 15
PostgreSQL - Joins in PostgreSQL
This query returns fewer rows than expected:
SELECT * FROM A FULL OUTER JOIN B ON A.id = B.id WHERE A.id IS NOT NULL;
Why?
AON clause is incorrect
BFULL OUTER JOIN does not work with WHERE clauses
CWHERE clause filters out rows where A.id is NULL, losing unmatched B rows
DA.id cannot be NULL in FULL OUTER JOIN
Step-by-Step Solution
Solution:
  1. Step 1: Understand WHERE filtering effect

    WHERE A.id IS NOT NULL removes rows where A.id is NULL, which are unmatched rows from B.
  2. Step 2: Impact on FULL OUTER JOIN result

    This filtering reduces rows, losing unmatched rows from B side.
  3. Final Answer:

    WHERE clause filters out rows where A.id is NULL, losing unmatched B rows -> Option C
  4. Quick Check:

    Filtering NULLs removes unmatched rows = A [OK]
Quick Trick: Filter NULLs carefully after FULL OUTER JOIN to keep all rows [OK]
Common Mistakes:
  • Assuming WHERE does not affect join result
  • Confusing ON and WHERE clauses
  • Expecting FULL OUTER JOIN to ignore WHERE filters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes