Home › Learn › SQL › Changing data, and the report

UPDATE

Lesson 22 of 26. Change existing rows.

UPDATE products SET price = price * 0.9 WHERE category = 'stationery'; changes the matching rows; the SET expression can use the row's current values. Several columns change with SET a = 1, b = 2.

An UPDATE without a WHERE changes every row in the table. Databases do exactly what you say, so the habit is to write the WHERE first, run it as a SELECT to see which rows it picks, and only then turn it into an UPDATE.

UPDATE employees SET salary = salary + 500 WHERE dept = 'Support';

Your task

Reduce the price of every product in the stationery category by 10 percent.

Hint 1

SET price = price * 0.9 WHERE category = 'stationery'

Show the solution
UPDATE products SET price = price * 0.9 WHERE category = 'stationery';

    Runs SQLite compiled to WebAssembly in this tab; the database is rebuilt before every run.