Update a single row
UPDATE users
SET email = "new@mail.com"
WHERE id = 5;
Matching on a unique key like id guarantees you change exactly one row. The WHERE clause is what keeps the change targeted.
Update several columns at once
UPDATE products
SET price = 19.99, in_stock = 1
WHERE sku = "A100";
Separate each column assignment with a comma. All of them are applied to every row that matches the condition.
Update many rows with a condition
UPDATE orders
SET status = "shipped"
WHERE status = "packed";
A broader WHERE updates every matching row, which is useful for bulk changes like marking all packed orders as shipped.
Common mistakes / tips
- Always use WHERE. Without it, UPDATE changes every row in the table.
- Test with SELECT first. Run the same
WHEREin aSELECTto confirm which rows it hits. - Back up before bulk updates. A wrong condition can be hard to undo.
Frequently asked questions
What happens if I forget the WHERE clause?
The update applies to every row in the table. Always include a WHERE, and preview the affected rows with a SELECT before running the update.
How do I update a row based on another table?
Join the tables in the update, for example UPDATE orders o JOIN customers c ON o.customer_id = c.id SET o.region = c.region; copies a value across.
Want to practise UPDATE safely on real tables? Our free SQL course lets you run queries in your browser.