Bird
0
0

Which SQL join syntax is correct for joining two tables employees and departments on department_id?

easy📝 Syntax Q12 of 15
SQL - Advanced Joins
Which SQL join syntax is correct for joining two tables employees and departments on department_id?
ASELECT * FROM employees JOIN departments USING employees.department_id = departments.department_id;
BSELECT * FROM employees JOIN departments WHERE employees.department_id = departments.department_id;
CSELECT * FROM employees, departments ON employees.department_id = departments.department_id;
DSELECT * FROM employees JOIN departments ON employees.department_id = departments.department_id;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct JOIN syntax

    The correct syntax uses JOIN ... ON condition to specify join keys.
  2. Step 2: Check each option

    SELECT * FROM employees JOIN departments ON employees.department_id = departments.department_id; uses JOIN ... ON correctly. USING with a full equality condition is invalid as USING expects column names only. JOIN ... WHERE is invalid syntax for explicit joins. Comma-separated tables with ON is invalid.
  3. Final Answer:

    SELECT * FROM employees JOIN departments ON employees.department_id = departments.department_id; -> Option D
  4. Quick Check:

    JOIN ... ON is correct syntax [OK]
Quick Trick: Use JOIN ... ON for correct join syntax [OK]
Common Mistakes:
MISTAKES
  • Using WHERE instead of ON for join condition
  • Mixing comma joins with ON clause
  • Incorrect USING clause syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes