How to decrease value by all cells in the column in MySQL query?
Question
I am bit novice regarding databases and I will highly appreciate any help given.
I need to decrease all cells by X in one column of a table. Do I need to select the table and the column and use the value as variable like $value=$value +/- X;
Solution
Well then simply do so by
UPDATE yourtablename SET columnname = columname-1
(if your column/cell is of a integer type this works fine) and dont enter a WHERE CLAUSE (updating all rows)
OTHER TIPS
Try this,
UPDATE tableName
SET colName = colName - 5 -- this will decrease the value by 5
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow