Bird
0
0

Consider tables:

medium📝 query result Q5 of 15
PostgreSQL - Joins in PostgreSQL
Consider tables:
employees(emp_id, name, dept_id)
departments(dept_id, name)
What is the output of:
SELECT * FROM employees NATURAL JOIN departments;?
ARows joined on <code>emp_id</code> only.
BRows joined on <code>dept_id</code> only, with one <code>name</code> column merged.
CRows joined on both <code>dept_id</code> and <code>name</code> columns.
DRows joined without any filtering.
Step-by-Step Solution
Solution:
  1. Step 1: Identify common columns

    Both tables have columns dept_id and name.
  2. Step 2: NATURAL JOIN matches all common columns

    Join happens where both dept_id and name are equal in both tables.
  3. Final Answer:

    Rows joined on both dept_id and name columns. -> Option C
  4. Quick Check:

    NATURAL JOIN matches all common columns = Rows joined on both dept_id and name columns. [OK]
Quick Trick: NATURAL JOIN merges all same-named columns in join condition [OK]
Common Mistakes:
  • Assuming only one column is used for join
  • Expecting separate columns for same names
  • Thinking NATURAL JOIN ignores common columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes