Skip to content
Advertisement

MySQL Update Column +1?

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.

Advertisement

Answer

The easiest way is to not store the count, relying on the COUNT aggregate function to reflect the value as it is in the database:

You can create a view to house the query mentioned above, so you can query the view just like you would a table…

But if you’re set on storing the number, use:

..replacing “?” with the appropriate value.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement