Bird
0
0

Given two tables:

medium📝 query result Q13 of 15
PostgreSQL - Joins in PostgreSQL
Given two tables:
students(id, name, class)
enrollments(id, class, grade)
What will be the result of this query?
SELECT * FROM students NATURAL JOIN enrollments;
AAll rows from students combined with all rows from enrollments.
BRows where both <code>id</code> and <code>class</code> match in both tables.
CRows where only <code>class</code> matches in both tables.
DRows where only <code>id</code> matches in both tables.
Step-by-Step Solution
Solution:
  1. Step 1: Identify common columns

    Both tables share columns id and class.
  2. Step 2: Understand NATURAL JOIN behavior

    NATURAL JOIN matches on all columns with the same names, so it joins on both id and class.
  3. Final Answer:

    Rows where both id and class match in both tables. -> Option B
  4. Quick Check:

    NATURAL JOIN matches all common columns [OK]
Quick Trick: NATURAL JOIN uses all same-named columns to join [OK]
Common Mistakes:
  • Assuming join on only one common column
  • Confusing NATURAL JOIN with JOIN USING
  • Expecting Cartesian product instead of filtered rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes