R
R
Rodion Yurchenko2015-11-28 08:19:16
MySQL
Rodion Yurchenko, 2015-11-28 08:19:16

How to increase the value of a cell in all rows of a table?

Good afternoon
There is a table with a million records
The table has an int field (position)
Help me write a query that will increase the position value in ALL records by 1
Can this be done in pure SQL?
If not, then you can add python

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Marat, 2015-11-28
@aassdds

It is possible without where:
An important point, decide what to do if the field value is null - write 1 or leave null. If the first - add the second command update table1 set col1=1 where col is null, if the second - the first command will suffice.

D
Dmitry Kovalsky, 2015-11-28
@dmitryKovalskiy

Have you tried simple?

UPDATE table1
SET col1 = col1+1
WHERE 1=1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question