Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Inserting data
Modifying data
10. Modify multiple rows
Deleting data
CRUD

Instruction

Excellent! When you write an UPDATE query, the database modifies all rows for which the WHERE condition is true. You can modify many rows with one UPDATE command. You can build up your WHERE condition with AND, OR, and NOT. You can also use any other condition you would use in a SELECT command.

To change the age value for all users with an id lower than 4, you can run the command:

UPDATE user 
SET
  age = 17 
WHERE id < 4; 

The database always tells you how many rows have actually been modified. In the previous examples, it only modified a single row each time. Always check the number of modified rows to see if your query did what you expected it to.

Exercise

It's happy hour at our restaurant! Change the price of all main courses to 20.

Stuck? Here's a hint!

Type:

UPDATE dish 
SET
  price = 20 
WHERE type = 'main course';