Bird
0
0

Given the tables:

medium📝 query result Q13 of 15
SQL - INNER JOIN
Given the tables:
Employees(id, name, dept_id)
Departments(dept_id, dept_name)
What is the result of this query?
SELECT name, dept_name FROM Employees INNER JOIN Departments ON Employees.dept_id = Departments.dept_id;

Assuming:
Employees: (1, 'Alice', 10), (2, 'Bob', 20), (3, 'Carol', 30)
Departments: (10, 'HR'), (20, 'Sales')
A[('Alice', 'HR'), ('Bob', 'Sales')]
B[('Alice', 'HR'), ('Bob', 'Sales'), ('Carol', '30')]
C[('Alice', 'HR'), ('Bob', 'Sales'), ('Carol', NULL)]
D[('Alice', 'HR'), ('Bob', 'Sales'), ('Carol', 'Finance')]
Step-by-Step Solution
Solution:
  1. Step 1: Identify matching rows by dept_id

    Employees with dept_id 10 and 20 match Departments with same dept_id. Carol's dept_id 30 has no match.
  2. Step 2: Understand INNER JOIN output

    INNER JOIN returns only rows with matching dept_id in both tables, so Carol is excluded.
  3. Final Answer:

    [('Alice', 'HR'), ('Bob', 'Sales')] -> Option A
  4. Quick Check:

    INNER JOIN excludes unmatched rows [OK]
Quick Trick: INNER JOIN excludes rows without matching keys [OK]
Common Mistakes:
MISTAKES
  • Including unmatched rows in result
  • Assuming NULL values appear for unmatched rows
  • Confusing INNER JOIN with LEFT JOIN behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes