MySQL Forums
Forum List  »  Newbie

Populating columns with sequential values
Posted by: Michael Smith
Date: January 31, 2023 12:53AM

I am trying to populate a column (order2) with sequential values (10,20,30 ...) where the table is ordered on the values in order1 .

I have come up with code as below:

Select * from products01 order by order1;
SELECT @i:=0;
UPDATE products01 SET order2 = @i:=@i+10;

The products file is naturally ordered on the product number with auto-increment.

I am unable to get the table to order by order1 while I populate order2.

Any thoughts?

Mike Smith

Options: ReplyQuote

Written By
Populating columns with sequential values
January 31, 2023 12:53AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.