How to increase value by a certain number?

Example 1 (for all rows):

UPDATE product SET price = price + 50

Example 2 (for a specific row):

UPDATE product SET price = price + 50 WHERE id = 1

Example 3 (for specific rows):

UPDATE product SET price = price + 50 WHERE id IN [1, 2, 3]

Example 4 (generic):

UPDATE {table} SET {column} = {column} + {value} WHERE {condition}

Where:

  • {table} – table name
  • {column} – column name
  • {value} – a number by which column’s value should be increased or decreased
  • {condition} – some condition if any

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)