How to make execution update reverse query mysql by id? -
i have 5 rows id: 1,2,3,4,5.
then made query try change id to: 2,3,4,5,6
update table set `id` = `id` + 1
then get:
duplicate entry '2' key 'primary'.
i understand query executed id 1 first , cause primary 2 existed.
so question how make query has been executed id 5 1.
created table num_sample numbers 1 100. defined primary key on column num. , wrote update
update num_sample set num = num + 1 order num desc limit 100;
worked absolutely fine in mysql.
Comments
Post a Comment