View Single Post

   
  #8 (permalink)  
Old 02-28-2008, 06:48 AM
=?ISO-8859-1?Q?Olav_M=F8rkrid?=
 
Posts: n/a
Default Re: giving a row the new highest id

wait, let's make it even more interesting

what if you want to update more than one row, and each row should have
a successive new id. is that possible in one statement?

i tried just removing the where statement in barons suggestion, which
fails as i guess the select is computed only once prior to being used
in the update/set.

mysql> update test set id = (select id + 1 from ( select max(id) as id
from test ) as x);
ERROR 1062 (23000): Duplicate entry '424' for key 1

is it possible, or do i have to do the rows one by one?
Reply With Quote