I have a db table containing a column display_order. The data looks like this:
2
4
7
10
12
I want to update the same db column and it should look like this:
1
2
3
4
5
Please suggest some easy SQL code.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Have a look into ROW_NUMBER(), this will help you here.
e.g. demo that won’t update your data, but will show you the current order and the new order based on ROW_NUMBER
If that produces what you’d expect, then you can just switch it into an UPDATE statement.