Recall & Review
beginner
What does the RETURNING clause do in an UPDATE statement?
It returns the updated rows immediately after the UPDATE operation, showing the new values without needing a separate SELECT query.
Click to reveal answer
beginner
Write a simple UPDATE statement with RETURNING to change a user's email and get the updated email back.
UPDATE users SET email = 'newemail@example.com' WHERE id = 1 RETURNING email;
Click to reveal answer
intermediate
Why is using RETURNING in UPDATE useful compared to running UPDATE then SELECT?
It saves time and resources by combining update and retrieval in one step, reducing the number of queries and network traffic.
Click to reveal answer
intermediate
Can RETURNING clause return multiple columns? Give an example.
Yes, it can return multiple columns. Example: UPDATE products SET price = price * 1.1 RETURNING id, price;
Click to reveal answer
beginner
What happens if no rows match the UPDATE condition when using RETURNING?
No rows are updated and the RETURNING clause returns an empty result set.
Click to reveal answer
What is the purpose of the RETURNING clause in an UPDATE statement?
✗ Incorrect
The RETURNING clause returns the updated rows right after the UPDATE operation.
Which of the following is a valid use of RETURNING in PostgreSQL?
✗ Incorrect
Option D correctly places RETURNING after the SET clause to return specified columns.
If an UPDATE statement with RETURNING affects no rows, what is returned?
✗ Incorrect
No rows updated means RETURNING returns an empty result set.
Can RETURNING be used to get the old values before update?
✗ Incorrect
RETURNING returns the new values after update; old values require triggers or other methods.
Which SQL dialect supports UPDATE with RETURNING clause?
✗ Incorrect
PostgreSQL supports UPDATE with RETURNING; MySQL and SQLite do not support it natively.
Explain how the RETURNING clause works in an UPDATE statement and why it is useful.
Think about how you get updated data without a second query.
You got /3 concepts.
Write an example UPDATE query using RETURNING to update a record and get back multiple columns.
Use RETURNING after SET and list columns separated by commas.
You got /4 concepts.