Bird
0
0

Consider this SQL query:

medium📝 Debug Q14 of 15
SQL - Set Operations
Consider this SQL query:
SELECT name FROM employees UNION ALL SELECT name FROM departments;
It returns an error. What is the most likely cause?
AThe two SELECT statements have different numbers of columns.
BUNION ALL cannot be used with SELECT statements.
CThe keyword ALL is not allowed after UNION.
DThe tables employees and departments must have the same name.
Step-by-Step Solution
Solution:
  1. Step 1: Check column counts in both SELECTs

    UNION ALL requires both SELECTs to have the same number of columns.
  2. Step 2: Identify error cause

    If employees and departments tables have different columns selected, error occurs.
  3. Final Answer:

    The two SELECT statements have different numbers of columns. -> Option A
  4. Quick Check:

    Column count mismatch causes error = C [OK]
Quick Trick: Both SELECTs must have same columns count [OK]
Common Mistakes:
MISTAKES
  • Thinking UNION ALL disallows duplicates only
  • Assuming table names must match
  • Believing ALL keyword is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes