Update Rows with RETURNING Clause in PostgreSQL
📖 Scenario: You manage a small bookstore database. You want to update the prices of some books and see which books were changed immediately.
🎯 Goal: Build a SQL query that updates book prices and returns the updated rows using the RETURNING clause.
📋 What You'll Learn
Create a table called
books with columns id, title, and priceInsert 3 specific books with given prices
Write an
UPDATE statement to increase prices by 10% for books priced below 20Use the
RETURNING clause to get the updated rows💡 Why This Matters
🌍 Real World
Updating product prices or user information in a database and immediately seeing which records changed is common in business applications.
💼 Career
Knowing how to update data and retrieve the changed rows efficiently is a valuable skill for database administrators and backend developers.
Progress0 / 4 steps