dimanche 12 juillet 2020

SQL Query with Group , Order by and Random at the same time

First is difficult to me to explain this because my english, and since i tried to make the simplest example as possible i was unable to find anything similar to this problem..

OK. As we see John and David has more than one row and there's a Order column so we can order it simply using ORDER BY Name ASC, Order ASC but this is not exactly what i need..

enter image description here

Here is the problem: i would like to know if its possible to order by name and make some kind of group for each name, then by order by its Order, and then apply a final ORDER BY RAND() so you still viewing all the rows from david, mark, john and William, but in random order..

enter image description here

So every time you make a query, the order is completely random but still with some order..

enter image description here

Sorry my explanation because my english, and because i cant find other way to explain it.. Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire