Bird
0
0

You have two tables:

hard📝 Application Q15 of 15
SQL - Set Operations

You have two tables:

Employees(emp_id INT, emp_name VARCHAR, dept VARCHAR)
Managers(manager_id INT, manager_name VARCHAR)

You want to combine employee and manager names into one list using a set operation. Which query correctly applies set operation column matching rules?

A) SELECT emp_id, emp_name FROM Employees UNION SELECT manager_id, manager_name FROM Managers;
B) SELECT emp_name FROM Employees UNION SELECT manager_name FROM Managers;
C) SELECT emp_name, dept FROM Employees UNION SELECT manager_name, manager_id FROM Managers;
D) SELECT emp_id, emp_name, dept FROM Employees UNION SELECT manager_id, manager_name FROM Managers;
ASELECT emp_name FROM Employees UNION SELECT manager_name FROM Managers;
BSELECT emp_id, emp_name FROM Employees UNION SELECT manager_id, manager_name FROM Managers;
CSELECT emp_name, dept FROM Employees UNION SELECT manager_name, manager_id FROM Managers;
DSELECT emp_id, emp_name, dept FROM Employees UNION SELECT manager_id, manager_name FROM Managers;
Step-by-Step Solution
Solution:
  1. Step 1: Identify columns to combine

    You want a list of names only, so selecting one column (name) from each table is appropriate.
  2. Step 2: Check column counts and types

    SELECT emp_name FROM Employees UNION SELECT manager_name FROM Managers; selects one VARCHAR column from each table, matching count and compatible types. Other options have mismatched column counts or incompatible columns.
  3. Final Answer:

    SELECT emp_name FROM Employees UNION SELECT manager_name FROM Managers; -> Option A
  4. Quick Check:

    Same column count and type for names = B [OK]
Quick Trick: Select same number and type of columns to combine [OK]
Common Mistakes:
MISTAKES
  • Selecting different numbers of columns
  • Mixing incompatible column types
  • Including unrelated columns in set operation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes