UPDATE Statement in SQL

Level 4105 keystrokes

UPDATE changes existing rows; here it gives in-stock Electronics a 10% discount.

SQL code

-- Change rows of the products table
1UPDATE
2 products
3SET
-- Multiply the current price by 0.9, a 10% discount
4 price = price * 0.9,
-- Record when the row was changed
5 updated_at = NOW()
-- Only Electronics with stock; without WHERE, every row would be updated
6WHERE
7 category = 'Electronics'
8 AND stock > 0;

Output

Query OK, 15 rows affected
Rows matched: 15  Changed: 15  Warnings: 0
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this SQL code and how often they appear.

  • =× 3
  • '× 2
  • _× 1
  • ,× 1
  • ;× 1
  • .× 1
  • (× 1
  • )× 1
  • *× 1
  • >× 1

More SQL examples at level 4

← SQL typing practice