Brug order by
. Her er en metode:
select t.*
from (select t.*, (@rn := @rn + 1) as seqnum
from tickets t cross join
(select @rn := 0) params
order by vip desc, rand()
) t
order by (seqnum = 1) desc, price asc;
Dette bruger underforespørgslen til at identificere den ene række, der skal holdes øverst. Så bruger den disse oplysninger til bestilling i den ydre forespørgsel.
Hvis dine rækker har en unik identifikator, kan du også gøre:
select t.*
from tickets t cross join
(select id from tickets where vip = 1 order by rand() limit 1) as t1
order by (t.id = t1.id) desc, price asc;