Results 1 to 2 of 2
Thread: Randomize results then sort
Nov 6, 2009, 21:02 #1
Randomize results then sort
Say I am querying a MySQL database of profiles under a certain city but I want those results randomized and then from that randomized order, sort by user level (admin, general, etc). I have looked at multiple solutions online with ORDER BY and GROUP BY but whenever an ORDER BY RAND() query happens followed by GROUP BY user_level, it doesn't keep the admins at the top.
So in a nutshell I am looking to randomize all profiles from table but put the admins in the result first but randomize the admins at the top in addition to randomizing the general users at the bottom. Is this possible? I am using PHP by the way.
Nov 6, 2009, 21:55 #2
- Join Date
- Aug 2000
- Philadephia, PA
- 1 Post(s)
- 0 Thread(s)
SELECT col1, col2, col3, user_level FROM (SELECT col1, col2, col3, user_level FROM table ORDER BY RAND()) t1 ORDER BY user_levelTry Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more