I was wondering what would be the easiest way to update a column by +1? I will be updating a post count of a category based on when users submits a new post.
Thanks.
This question is related to
mysql
sql
sql-update
aggregate-functions
How about:
update table
set columnname = columnname + 1
where id = <some id>
update post set count = count + 1 where id = 101
update TABLENAME
set COLUMNNAME = COLUMNNAME + 1
where id = 'YOURID'
You can do:
UPDATE
categories
SET posts
= posts
+ 1 WHERE category_id
= 42;
update table_name set field1 = field1 + 1;
Source: Stackoverflow.com