M
M
Magzhan Birgebayuly2015-10-23 14:51:40
SQL
Magzhan Birgebayuly, 2015-10-23 14:51:40

How to make something like this: v = 0 UPDATE FROM t SET `menuindex` = v++;?

I have a table with a lot of data. I can sort it in the database, but I need to add the initial menu indexing, which will change over time.
v = 0 UPDATE FROM t SET `menuindex` = v++;
where v is an integer type
t is a table
as it is executed, the value will increase by 1.
Excuse: I don't know how to formulate a query in search engines...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2015-10-23
@henhanshi

What dialect of SQL?
For mysql: stackoverflow.com/questions/6617056/updating-colum...
For postgresql... However, by the characteristic ` in the column name, I think that you have mysql.

M
Magzhan Birgebayuly, 2015-10-26
@henhanshi

According to the link type such a solution:

SET @v := 0;
UPDATE FROM t SET `menuindex` = @v := @v+1;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question