update photo set order_id=0; update photo p,(SELECT @row := 0) r set p.order_id= (@row := @row + 1) where p.active=1 ;