Bird
0
0

Find the problem in this query:

medium📝 Debug Q7 of 15
SQL - Set Operations
Find the problem in this query:
SELECT id, name FROM staff UNION SELECT id, salary FROM payroll;
AColumn names must be the same in both SELECT statements.
BUNION cannot combine columns with different names.
CData types of the second columns differ and are incompatible.
DBoth SELECT statements must have ORDER BY clauses.
Step-by-Step Solution
Solution:
  1. Step 1: Compare columns in both SELECTs

    Both have 2 columns, but second columns are 'name' (likely VARCHAR) and 'salary' (likely numeric).
  2. Step 2: Check data type compatibility

    Different data types in same column position cause error in UNION.
  3. Final Answer:

    Data types of the second columns differ and are incompatible. -> Option C
  4. Quick Check:

    Data type mismatch error = B [OK]
Quick Trick: UNION columns must have compatible data types [OK]
Common Mistakes:
MISTAKES
  • Assuming column names must match
  • Ignoring data type differences
  • Expecting ORDER BY in both SELECTs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes