Bird
0
0

Consider two tables:

medium📝 query result Q4 of 15
SQL - Set Operations
Consider two tables:
Employees: emp_id
101
102
103

Contractors: emp_id
102
103
104

What will be the output of:
SELECT emp_id FROM Employees UNION ALL SELECT emp_id FROM Contractors;
A101, 102, 103, 104
B101, 102, 103, 102, 103, 104
C102, 103, 104
D101, 102, 103
Step-by-Step Solution
Solution:
  1. Step 1: Understand UNION ALL behavior

    UNION ALL combines all rows from both queries including duplicates.
  2. Step 2: List all emp_id values

    Employees has 101, 102, 103; Contractors has 102, 103, 104.
  3. Step 3: Combine results

    All values appear in the result, duplicates included: 101, 102, 103, 102, 103, 104.
  4. Final Answer:

    101, 102, 103, 102, 103, 104 -> Option B
  5. Quick Check:

    Duplicates are preserved in UNION ALL [OK]
Quick Trick: UNION ALL keeps duplicates; UNION removes them [OK]
Common Mistakes:
MISTAKES
  • Assuming duplicates are removed
  • Confusing UNION ALL with UNION
  • Listing only unique values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes