Bird
0
0

Consider the tables:

medium📝 query result Q5 of 15
PostgreSQL - Joins in PostgreSQL
Consider the tables:
Authors:
id | name
1 | John
2 | Mary

Books:
id | title
1 | Book A
2 | Book B
3 | Book C

What will be the output of:
SELECT name, title FROM Authors CROSS JOIN Books WHERE Authors.id = 2 ORDER BY name, title;?
ARows where author id equals 2 only
BRows where book id equals 2 only
CRows where author id or book id equals 2
DAll rows from CROSS JOIN without filtering
Step-by-Step Solution
Solution:
  1. Step 1: Understand WHERE clause effect

    The condition Authors.id = 2 unambiguously refers to the Authors table.
  2. Step 2: Determine filtered rows

    It filters to only author with id=2 (Mary) paired with all books.
  3. Final Answer:

    Rows where author id equals 2 only -> Option A
  4. Quick Check:

    WHERE Authors.id=2 filters to author id=2 [OK]
Quick Trick: Always qualify columns in WHERE after CROSS JOIN to avoid ambiguity [OK]
Common Mistakes:
  • Assuming WHERE filters both tables correctly without qualification
  • Ignoring ambiguous column error
  • Expecting no filtering without ON clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes