sql - MySQL table reorder -


i have table like

id - data
1 - ...
2 - ...
4 - ...
5 - ...
8 - ...
12 - ...

the table long, thousands ids. @ ids, there "empty" numbers between of them. want reorder ids have no empty ones.

table should like
1 - ...
2 - ...
3 - ...
4 - ...
etc.

how query like?

i don't advocate re-numbering ids. id column should primary key table, , gaps don't make difference. if used foreign key references, messing database.

but, can as:

set @rn = 0;  update `table` t     set t.id = (@rn := @rn + 1)     order t.id; 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -