Dette burde virke
update
content,
(
select
@row_number:=ifnull(@row_number, 0)+1 as new_position,
ContentID
from content
where CategoryID=1
order by position
) as table_position
set position=table_position.new_position
where table_position.ContentID=content.ContentID;
Men jeg ville foretrække at anvende dette først, for at deaktivere brugerdefineret variabel
set @row_number:=0;
Tilføjet af Mchl:
Du kan gøre det i en erklæring som denne
update
content,
(
select
@row_number:=ifnull(@row_number, 0)+1 as new_position,
ContentID
from content
where CategoryID=1
order by position
) as table_position,
(
select @row_number:=0
) as rowNumberInit
set position=table_position.new_position
where table_position.ContentID=content.ContentID;