Bird
0
0

Given tables:

medium📝 query result Q4 of 15
SQL - INNER JOIN
Given tables:
Employees(id, name, dept_id)
Departments(dept_id, dept_name)
What will this query return?
SELECT Employees.name, Departments.dept_name FROM Employees INNER JOIN Departments ON Employees.dept_id = Departments.dept_id;
AAll employees with their department names where dept_id matches
BAll employees including those without a department
CAll departments including those without employees
DAn error because dept_id is ambiguous
Step-by-Step Solution
Solution:
  1. Step 1: Understand INNER JOIN effect on these tables

    INNER JOIN returns rows where Employees.dept_id matches Departments.dept_id, so only employees with matching departments appear.
  2. Step 2: Analyze options

    All employees with their department names where dept_id matches correctly describes this. All employees including those without a department would be LEFT JOIN. All departments including those without employees would be RIGHT JOIN. An error because dept_id is ambiguous is incorrect because dept_id is qualified properly.
  3. Final Answer:

    All employees with their department names where dept_id matches -> Option A
  4. Quick Check:

    INNER JOIN returns matching rows only [OK]
Quick Trick: INNER JOIN returns only rows with matching keys in both tables [OK]
Common Mistakes:
MISTAKES
  • Thinking INNER JOIN returns unmatched rows
  • Assuming ambiguous column error without qualification
  • Confusing INNER JOIN with LEFT or RIGHT JOIN

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes