Bird
0
0

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

easy📝 Syntax Q12 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 INTERSECT SELECT * FROM table2;
BSELECT * FROM table1 EXCEPT SELECT * FROM table2;
CSELECT * FROM table1 UNION EXCEPT SELECT * FROM table2;
DSELECT * FROM table1 EXCEPT ALL SELECT * FROM table2;
Step-by-Step Solution
Solution:
  1. Step 1: Identify EXCEPT syntax

    The correct syntax is: SELECT ... EXCEPT SELECT ... to get rows in first query not in second.
  2. Step 2: Check options for correct usage

    SELECT * FROM table1 EXCEPT SELECT * FROM table2; matches correct syntax; others misuse INTERSECT, UNION, or EXCEPT ALL (which is valid but different).
  3. Final Answer:

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

    EXCEPT syntax = SELECT ... EXCEPT SELECT ... [OK]
Quick Trick: Use EXCEPT between two SELECTs to find rows only in first [OK]
Common Mistakes:
  • Using INTERSECT instead of EXCEPT
  • Adding UNION incorrectly
  • Using EXCEPT ALL when not needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes