Bird
0
0

Which of the following is the correct syntax to find rows in table1 but not in table2 using EXCEPT?

easy📝 Syntax Q3 of 15
PostgreSQL - Set Operations and Advanced Queries
Which of the following is the correct syntax to find rows in table1 but not in table2 using EXCEPT?
ASELECT * FROM table1 UNION SELECT * FROM table2;
BSELECT * FROM table1 INTERSECT SELECT * FROM table2;
CSELECT * FROM table1 EXCEPT SELECT * FROM table2;
DSELECT * FROM table1 MINUS SELECT * FROM table2;
Step-by-Step Solution
Solution:
  1. Step 1: Recall EXCEPT syntax

    EXCEPT is used as: SELECT ... FROM ... EXCEPT SELECT ... FROM ... to get rows in first query not in second.
  2. Step 2: Check other options

    INTERSECT returns common rows, UNION combines all rows, MINUS is not valid in PostgreSQL.
  3. Final Answer:

    SELECT * FROM table1 EXCEPT SELECT * FROM table2; -> Option C
  4. Quick Check:

    EXCEPT syntax correct = SELECT * FROM table1 EXCEPT SELECT * FROM table2; [OK]
Quick Trick: Use EXCEPT between two SELECTs for difference [OK]
Common Mistakes:
  • Using MINUS which is not in PostgreSQL
  • Confusing INTERSECT with EXCEPT
  • Incorrect order of queries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes