The UPDATE statement modifies existing rows in a table — changing a salary after a raise, correcting a typo in a name, or moving an employee to a new department. It's one of the most routine SQL operations, and also one of the most dangerous if you're not careful with it.

Basic Syntax

UPDATE employees
SET salary = 99000
WHERE id = 101;

Result:

Query OK, 1 row affected

You can update multiple columns in one statement by separating the assignments with commas:

UPDATE employees
SET department = 'Engineering', salary = salary + 5000
WHERE id = 103;

Notice salary = salary + 5000 — the right-hand side is evaluated using the row's current value before the update applies, so this reads as "add 5000 to whatever salary already is."

The WHERE Clause Is Not Optional

This is the single most important thing to understand about UPDATE: if you omit the WHERE clause, the statement updates every single row in the table, not just the one you had in mind.

-- DANGER: no WHERE clause — this gives EVERY employee the same salary
UPDATE employees
SET salary = 99000;

Result:

Query OK, 47 rows affected

That second example is a real, easy-to-make mistake — a missing semicolon that merges two statements, a copy-pasted query with the WHERE line accidentally deleted, or simply forgetting it entirely. Before running an UPDATE in a real environment, it's good practice to first run the equivalent SELECT with the same WHERE clause to confirm exactly which rows will be affected.

Updating Based on Another Table's Data

You can also drive an update using a subquery, which is useful when the new value depends on data elsewhere:

UPDATE employees
SET department = 'Unassigned'
WHERE department NOT IN (SELECT DISTINCT department FROM departments);

Once you're comfortable modifying rows, the next natural step is removing them entirely with the DELETE statement — which carries the exact same WHERE-clause warning, with even higher stakes.