Bird
0
0

What is the issue with this SQL query?

medium📝 Debug Q6 of 15
SQL - Set Operations

What is the issue with this SQL query?

SELECT employee_id, employee_name FROM Employees
UNION
SELECT id FROM Contractors;
AThe number of columns in both SELECT statements do not match.
BThe data types of columns do not match.
CUNION cannot be used between two different tables.
DThe query is correct and will execute without errors.
Step-by-Step Solution
Solution:
  1. Step 1: Count columns in each SELECT

    First SELECT returns 2 columns (employee_id, employee_name), second SELECT returns 1 column (id).
  2. Step 2: Check set operation rules

    UNION requires both SELECT statements to have the same number of columns.
  3. Final Answer:

    The number of columns in both SELECT statements do not match. is correct because the column counts differ.
  4. Quick Check:

    Column count mismatch causes error [OK]
Quick Trick: Both SELECTs must have same column count [OK]
Common Mistakes:
MISTAKES
  • Ignoring column count mismatch
  • Assuming UNION works with different column numbers
  • Confusing column names with counts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes