Bird
0
0

Identify the error in the following SQL set operation:

medium📝 Debug Q14 of 15
SQL - Set Operations

Identify the error in the following SQL set operation:

SELECT id, name FROM Customers
UNION
SELECT customer_id FROM Orders;
AColumn names do not match between queries.
BUNION cannot be used with SELECT statements.
CData types of columns are incompatible.
DThe second query has fewer columns than the first.
Step-by-Step Solution
Solution:
  1. Step 1: Compare column counts in both queries

    The first query selects 2 columns (id, name), the second selects only 1 column (customer_id). This mismatch causes an error.
  2. Step 2: Check other possible errors

    Column names do not need to match, and UNION works with SELECT statements. Data types are unknown but column count mismatch is enough to cause error.
  3. Final Answer:

    The second query has fewer columns than the first. -> Option D
  4. Quick Check:

    Column count mismatch = B [OK]
Quick Trick: Ensure both queries select same number of columns [OK]
Common Mistakes:
MISTAKES
  • Thinking column names must match
  • Ignoring column count mismatch
  • Assuming UNION works with different column counts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes