Bird
0
0

Which of the following is the correct syntax to join two tables Employees and Departments on the column DepartmentID?

easy📝 Syntax Q12 of 15
SQL - INNER JOIN
Which of the following is the correct syntax to join two tables Employees and Departments on the column DepartmentID?
ASELECT * FROM Employees WHERE DepartmentID = Departments.DepartmentID;
BSELECT * FROM Employees JOIN Departments ON Employees.DepartmentID = Departments.DepartmentID;
CSELECT * FROM Employees JOIN Departments USING (DepartmentID);
DSELECT * FROM Employees JOIN Departments ON Employees.ID = Departments.ID;
Step-by-Step Solution
Solution:
  1. Step 1: Check the JOIN condition syntax

    The correct JOIN syntax uses ON with matching columns: Employees.DepartmentID = Departments.DepartmentID.
  2. Step 2: Verify the options

    SELECT * FROM Employees JOIN Departments ON Employees.DepartmentID = Departments.DepartmentID; uses correct ON syntax with matching columns. SELECT * FROM Employees WHERE DepartmentID = Departments.DepartmentID; uses WHERE incorrectly. SELECT * FROM Employees JOIN Departments USING (DepartmentID); uses USING with correct parentheses. SELECT * FROM Employees JOIN Departments ON Employees.ID = Departments.ID; joins on wrong columns.
  3. Final Answer:

    SELECT * FROM Employees JOIN Departments ON Employees.DepartmentID = Departments.DepartmentID; -> Option B
  4. Quick Check:

    JOIN with ON and matching columns = SELECT * FROM Employees JOIN Departments ON Employees.DepartmentID = Departments.DepartmentID; [OK]
Quick Trick: Use JOIN ... ON table1.col = table2.col for correct syntax [OK]
Common Mistakes:
MISTAKES
  • Using WHERE instead of ON for JOIN condition
  • Joining on wrong columns
  • Misusing USING without parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes