Tried that in mysql5.0
I have a table test with column id,element, dataidx
I suppose the table in your last situation ie dataix goes from 1 to 6.
I assume that for a given id( or dataRow_id) I get a dataIndex in a specific range with no holes (like 4 5 6 and not like 4 7 9)
I need to duplicate table test in test2 because mysql doesn't support having a select on the same table than the update
Code:
insert into test2 select * from test;
update test t set dataidx=dataidx-(select min(t2.dataidx) from test2 t2 where t2.id=t.id);
You can drop the duplicate table.
Hope it helped.