Bird
0
0

Consider the table tasks(id INT, status TEXT) with rows:

medium📝 query result Q5 of 15
PostgreSQL - Set Operations and Advanced Queries
Consider the table tasks(id INT, status TEXT) with rows:
(1, 'pending'), (2, 'done'), (3, 'pending')
What will this query return?
DELETE FROM tasks WHERE status = 'pending' RETURNING id;
A(1), (2), (3)
B(2)
C(1), (3)
DNo rows returned
Step-by-Step Solution
Solution:
  1. Step 1: Identify rows matching DELETE condition

    Rows with status 'pending' are id 1 and 3.
  2. Step 2: Understand RETURNING output

    RETURNING id returns the ids of deleted rows, which are 1 and 3.
  3. Final Answer:

    (1), (3) -> Option C
  4. Quick Check:

    DELETE RETURNING returns deleted rows only [OK]
Quick Trick: RETURNING shows deleted rows matching WHERE [OK]
Common Mistakes:
  • Expecting rows with status 'done' to be deleted
  • Assuming all rows are returned
  • Ignoring WHERE clause in DELETE

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes