Bird
0
0

Consider this query:

medium📝 Debug Q14 of 15
PostgreSQL - Joins in PostgreSQL
Consider this query:
SELECT * FROM A FULL OUTER JOIN B ON A.id = B.id WHERE A.name = 'Alice';
Why might this query return fewer rows than expected?
ABecause the WHERE clause filters out rows where A.name is NULL, excluding unmatched rows from B.
BBecause FULL OUTER JOIN only returns matching rows.
CBecause the ON condition is incorrect syntax.
DBecause the query needs GROUP BY to include all rows.
Step-by-Step Solution
Solution:
  1. Step 1: Understand FULL OUTER JOIN with WHERE clause

    FULL OUTER JOIN returns all rows, but WHERE filters after join. Filtering on A.name excludes rows where A.name is NULL (unmatched in A).
  2. Step 2: Effect of filtering on unmatched rows

    Rows unmatched in A have NULL for A.name, so WHERE A.name = 'Alice' removes them, reducing rows.
  3. Final Answer:

    Because the WHERE clause filters out rows where A.name is NULL, excluding unmatched rows from B. -> Option A
  4. Quick Check:

    WHERE filters after join, can exclude NULLs [OK]
Quick Trick: Use WHERE carefully; it filters after join, may exclude NULLs [OK]
Common Mistakes:
  • Thinking FULL OUTER JOIN ignores WHERE filters
  • Assuming ON clause filters rows after join
  • Believing GROUP BY affects join row count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes