Platform: SQLite on Android.
Problem: table has three columns – id, title and order. Data in table has some “duplicate” order records, for example, there are 2 records with order “3” (example bellow). Order value also have “holes” in them – for example, there is no order value “2”.
Example table and select to pull it: *select _id,title,order from table order by order;*
_id TITLE ORDER
---------- ---------- ----------
5 First 0
19 Second 1
1 Third 3
4 Fourth 3
3 Fifth 5
16 Sixt 7
What is needed? Is there a way to update current records in table to “reset” values in ORDER column, while preserving as much as possible. Possible result after update that would be optimal is:
_id TITLE ORDER
---------- ---------- ----------
5 First 0
19 Second 1
1 Third 2
4 Fourth 3
3 Fifth 4
16 Sixt 5
Anyone has idea how to do this on SQLite running on Android? If this was Oracle and SQLServer I could be using #temp tables or cursors, but here…?
There may be a better solution, but I would simply select and save them into an array in the order that you want. Then you can loop through with a for loop and update the ORDER field for each record using the for loops iterator value.