SitePoint Sponsor |
|
User Tag List
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
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Code:SELECT col1, col2, col3, user_level FROM (SELECT col1, col2, col3, user_level FROM table ORDER BY RAND()) t1 ORDER BY user_level
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
Bookmarks