Bird
0
0

Why does this query cause an error?

medium📝 Debug Q7 of 15
PostgreSQL - Set Operations and Advanced Queries
Why does this query cause an error?
SELECT id, name FROM Table1 UNION SELECT id FROM Table2;
ADifferent number of columns in SELECT statements
BUNION requires ORDER BY clause
CTable1 and Table2 must have same number of rows
DUNION cannot combine different tables
Step-by-Step Solution
Solution:
  1. Step 1: Check column counts in SELECTs

    The first SELECT returns 2 columns (id, name), second returns 1 column (id). UNION requires same number of columns.
  2. Step 2: Verify other options

    ORDER BY is optional, tables can differ in rows, UNION can combine different tables.
  3. Final Answer:

    Different number of columns in SELECT statements -> Option A
  4. Quick Check:

    UNION requires same column count [OK]
Quick Trick: UNION needs same number of columns in both SELECTs [OK]
Common Mistakes:
  • Mismatched column counts
  • Assuming ORDER BY is required
  • Thinking UNION needs same row count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes