UPDATE with subquery preview
📖 Scenario: You manage a small bookstore database. You want to update the prices of some books based on their current prices.
🎯 Goal: Build an UPDATE SQL query that uses a subquery to preview the new prices before applying the update.
📋 What You'll Learn
Create a table called
books with columns id, title, and price.Insert 3 books with exact titles and prices.
Create a subquery that selects the
id and the new price (current price + 5).Write an
UPDATE statement that uses the subquery to update the prices.💡 Why This Matters
🌍 Real World
Updating prices in a product database based on calculated values is common in retail and inventory management.
💼 Career
Knowing how to use UPDATE with subqueries helps database administrators and developers maintain accurate and dynamic data.
Progress0 / 4 steps