Bird
0
0

Given tables:

medium📝 query result Q4 of 15
PostgreSQL - Joins in PostgreSQL
Given tables:
employees(id, name)
departments(id, dept_name)
What will this query return?
SELECT employees.name, departments.dept_name FROM employees INNER JOIN departments ON employees.id = departments.id;
ASyntax error due to wrong JOIN condition
BAll employees with all department names regardless of id
CAll employees with their matching department names where ids match
DOnly employees without departments
Step-by-Step Solution
Solution:
  1. Step 1: Understand INNER JOIN behavior

    INNER JOIN returns rows where the join condition matches in both tables.
  2. Step 2: Analyze the query condition

    It joins employees and departments where employees.id equals departments.id, returning matching pairs.
  3. Final Answer:

    All employees with their matching department names where ids match -> Option C
  4. Quick Check:

    INNER JOIN = matching rows only [OK]
Quick Trick: INNER JOIN returns only matching rows from both tables [OK]
Common Mistakes:
  • Thinking INNER JOIN returns all rows from both tables
  • Assuming it returns unmatched rows
  • Believing the query has syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes