Changing Rows with UPDATE

Data doesn't only grow, it also changes: a customer moves, a game gets a new price. UPDATE changes rows that are already in a table. Oscar King has moved from Bristol to London:

UPDATE customers
SET city = 'London'
WHERE id = 10;

After UPDATE comes the table. After SET comes the column and, after the equals sign, its new value. And WHERE says which rows to change, exactly as in a query: the statement changes every row that the condition finds, and no other. Results shows Rows changed: 1, and a query shows the change:

SELECT name, city
FROM customers
WHERE city = 'London';
namecity
Emma ClarkLondon
Olivia BrownLondon
Leo WalkerLondon
Oscar KingLondon
Grace HallLondon

To change several columns at once, separate them with commas: SET city = 'London', email = 'oscar@king.dev'. In SET, the equals sign means “store this value”, while in WHERE, it compares. That's also how you clear a value: SET city = NULL (but to find empty values, you write WHERE city IS NULL, as you know).

To change one particular row, find it by its primary key, as above with WHERE id = 10. Names can repeat (two customers can both be called Oscar King) and text must match exactly, but an ID always means one row.

In the WHERE of an UPDATE, you can use everything you know: AND, OR, IN, LIKE, BETWEEN, functions and even subqueries. An UPDATE can change one row, many rows or none: when the condition finds nothing, that's not an error, the statement just changes nothing (Rows changed: 0).

Typical mistake: a WHERE that finds nothing, for example because of a typo: WHERE name = 'Oscar Kng'. You get no error, and the result of your query looks as if nothing had happened. When the change isn't there, look at Rows changed: if it says 0, the WHERE didn't find any row.

Instructions

Mia Lewis (ID 7) has moved from Bristol to Manchester, and she has a new email: mia@lewis.me. Change both with one UPDATE.

Below it, show the ID, name, email and city of the customers from Manchester, sorted by ID:

idnameemailcity
2Liam Turnerliam.t@mail.comManchester
6Jack Harrisjack@harris.ioManchester
7Mia Lewismia@lewis.meManchester
13Sophie Adamssophie.adams@mail.comManchester

Robot Rebellion (ID 18) finally has a release date: it comes out on 2026-03-20. Set it with another UPDATE, and then show the title and release date of the games released on 2025-06-01 or later, sorted by release date:

titlereleased
Turbo Karts2025-06-05
Goal Rush2025-09-26
Knight's Oath2025-11-14
Robot Rebellion2026-03-20

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

3/9