mysql - My SQL query order so that no same value from the column come together -


i m fetching data multiple tables , want sort result no 2 values come together.

for example query returns following data.

23

25

26

26

22

22

19

i want result ordered no 2 values come consuctivley.

23

25

26

22

26

22

19

you cannot guarantee no 2 values come (for instance, values might same). can distribute them. here method using subquery , variables:

select t.* (select q.*,              (@rn := if(@v = col, @rn + 1,                         if(@v := col, 1, 1)                        )              ) rn       (query) q cross join            (select @v := -1, @rn := 0) vars       order col      ) t order rn, col; 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -