Reputation: 528
I've never had or attempted to do this before, but what I want to do is instead of getting the value out of the database and adding 1 to it just to do an update query is just do one UPDATE query and incrementing the field...
Is there a way of using a JOIN query to get the current value and then updating it again with the new one?
As it's literally just incrementing an INT number I thought there may be way around it.
Upvotes: 1
Views: 68
Reputation: 33431
Use this:
UPDATE yourtable SET yourcolumn = yourcolumn+1 WHERE yourid=123;
Upvotes: 1
Reputation: 29749
It's easy to increment a value in a cell:
UPDATE table SET column = column + 1 WHERE id = 123;
Upvotes: 0
Reputation: 60594
You could just do the following:
UPDATE table_name set field_to_increment = field_to_increment + 1 WHERE <cond>
Upvotes: 1
Reputation: 12518
update table_name set field_name=field_name + 1 where <condition>;
Upvotes: 7