I have a table which has rows inserted and removed which creates problems with the Sort Order. Sometimes I'm finding duplicate SortOrder values such as:
1 2 2 3 4 4
I reset the SortOrder values - I just can't seem to figure out the right query.
e.g.
Table1 contains columns: ssID, showID, sName, sDisplay, SortOrder
Primary Key is ssID
When new data gets inserted/removed I need to reset the SortOrder
New data is being inserted using a number of different procedures hence there's a need to clean the table up.
I can get the SortOrder values I want with this:
SET @t1=0;
SELECT *,
@t1 := @t1+1 As counter
FROM Table1
WHERE showID = 123
ORDER BY SortOrder ASC
From this, 'counter' is populated with 1, 2, 3, 4, 5 etc but I can't work out how to UPDATE the results from the SELECT to replace SortOrder with each new value from counter