Bird
0
0

Which of the following is the correct syntax to join two tables employees and departments on the column department_id?

easy📝 Syntax Q12 of 15
PostgreSQL - Joins in PostgreSQL
Which of the following is the correct syntax to join two tables employees and departments on the column department_id?
ASELECT * FROM employees JOIN departments ON employees.department_id = departments.department_id;
BSELECT * FROM employees WHERE department_id = departments.department_id;
CSELECT * FROM employees JOIN departments USING (department_id);
DSELECT * FROM employees JOIN departments ON employees.id = departments.id;
Step-by-Step Solution
Solution:
  1. Step 1: Check the JOIN syntax with ON clause

    The correct JOIN syntax uses ON to specify the matching columns: employees.department_id = departments.department_id.
  2. Step 2: Verify other options

    SELECT * FROM employees WHERE department_id = departments.department_id; uses WHERE incorrectly for joining. SELECT * FROM employees JOIN departments USING (department_id); uses correct USING syntax with parentheses. SELECT * FROM employees JOIN departments ON employees.id = departments.id; joins on wrong columns (id instead of department_id).
  3. Final Answer:

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

    JOIN with ON correct columns = C [OK]
Quick Trick: Use ON with matching columns for JOINs [OK]
Common Mistakes:
  • Using WHERE instead of ON for JOIN condition
  • Joining on wrong columns
  • Incorrect USING syntax without parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes