tags:

views:

167

answers:

1

Hi, is it possible to increase a certain value in a table by a certain number without reading last value and afterwards updating it?

i.e. I have columns "product" and "quality": product: iLamp quality: 50

I want to increase(or decrease) quality by x. To achieve this I am first reading last value (50), increasing or decreasing it, and writing it back.

Is there a direct way to complete this task?

+10  A: 

Sample 1 (for all rows):

UPDATE Products SET Price = Price + 50

Sample 2 (for a specific row):

UPDATE Products SET Price = Price + 50 WHERE ProductID = 1

Sample 3 (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
Koistya Navin
FROM is an SQLite keyword? The docs don't seem to indicate it. http://www.sqlite.org/lang_update.html
Jason S
ok, you fixed it, thanks.
Jason S