Bird
0
0

What is wrong with this query?

medium📝 Debug Q14 of 15
PostgreSQL - Set Operations and Advanced Queries
What is wrong with this query?
SELECT id, name FROM table1 EXCEPT SELECT id FROM table2;
AThe number of columns in both SELECTs differ
BEXCEPT cannot be used with SELECT statements
CThe query is missing a WHERE clause
DThe table names are invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check column counts in both SELECTs

    First SELECT returns two columns (id, name), second returns one column (id).
  2. Step 2: Understand EXCEPT requirements

    EXCEPT requires both SELECTs to have the same number and compatible types of columns.
  3. Final Answer:

    The number of columns in both SELECTs differ -> Option A
  4. Quick Check:

    EXCEPT needs equal columns [OK]
Quick Trick: EXCEPT requires same number of columns in both SELECTs [OK]
Common Mistakes:
  • Ignoring column count mismatch
  • Thinking EXCEPT needs WHERE clause
  • Assuming table names cause error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes