MySQL Increment value by N

This is a simple query to increment row value in MySQL. And this eliminates the need of code in php or other server side scripts.


UPDATE tablename
SET column_name=column_name + N
where clause;
Here, 'N' may be any number want to increment by.

UPDATE tablename
SET views = views + 1
where id=id;
Hence, the particular row will get updated increment by 1.
Usage: It is used commonly to update simple page views and so on.

Note: Do not forget where clause, then it will affect all the rows.
MySQL SQL Posted on 2016-04-05 03:01:27