- MySQL Update
Update statement
The UPDATE statement lets you edit an existing row in a table.
Format
UPDATE table_name
SET column_name = "new value"
WHERE row_name = "existing value"
For Example:
Your employer has asked you to remove $5000 from the balance of the person whose ID=1003.
The SQL statement would be:
UPDATE customer
SET Balance = Balance - 5000
WHERE id = 1003;
Result:
Let’s break down our statement:
UPDATE
is followed by the name of the tableSET
is followed by the column name- On our example, we have to remove $5000 from existing value. That’s why, we have to
SET
the Balance to be equal to Balance subtracted by $5000. - On the last line,
WHERE
clause is used to specify the name of the row from which we want to reduce the value.