Bird
0
0

You have two tables: Employees(emp_id, name, dept_id) and Departments(dept_id, dept_name). You want a view showing employee names with their department names. Which SQL creates this view correctly?

hard📝 Application Q9 of 15
SQL - Views
You have two tables: Employees(emp_id, name, dept_id) and Departments(dept_id, dept_name). You want a view showing employee names with their department names. Which SQL creates this view correctly?
ACREATE VIEW EmpDept AS SELECT e.name, d.dept_name FROM Employees e JOIN Departments d ON e.dept_id = d.dept_id;
BCREATE VIEW EmpDept AS SELECT name, dept_name FROM Employees, Departments;
CCREATE VIEW EmpDept AS SELECT emp_id, dept_id FROM Employees;
DCREATE VIEW EmpDept AS SELECT name, dept_name FROM Employees LEFT JOIN Departments;
Step-by-Step Solution
Solution:
  1. Step 1: Understand the join needed

    To combine employee names with department names, an INNER JOIN on dept_id is required.
  2. Step 2: Evaluate options

    CREATE VIEW EmpDept AS SELECT e.name, d.dept_name FROM Employees e JOIN Departments d ON e.dept_id = d.dept_id; uses JOIN with ON condition correctly; others miss join condition or use wrong syntax.
  3. Final Answer:

    CREATE VIEW EmpDept AS SELECT e.name, d.dept_name FROM Employees e JOIN Departments d ON e.dept_id = d.dept_id; -> Option A
  4. Quick Check:

    Correct join with ON clause = CREATE VIEW EmpDept AS SELECT e.name, d.dept_name FROM Employees e JOIN Departments d ON e.dept_id = d.dept_id; [OK]
Quick Trick: Use JOIN with ON to combine tables in views [OK]
Common Mistakes:
MISTAKES
  • Missing ON condition in JOIN
  • Using comma join without WHERE
  • Selecting unrelated columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes