|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
The topic almost says it all... I would like to make a SELECT query where the results is returned randomly every time I execute it... ie. one time the entries that starts with B comes first, then the rest... next time I run it I want another letter etc etc... basicly a link rotator... It doesn't have to give even results, ie. standard deviation...
![]() |
|
#2
|
|||
|
|||
|
In MySQL 3.23, you can however do: SELECT * FROM table_name ORDER BY RAND() This is useful to get a random sample of a set
My host run 3.22.27 and I don't think they will upgrade... is there another way? |
|
#3
|
|||
|
|||
|
This slightly more complicated method works in earlier versions of MySQL:
"SELECT id,field1,field2,field,etc,id*0+RAND() as random_record FROM mytable ORDER BY random_record" or "SELECT id,field1,field2,field,etc,id*0+RAND() as random_record FROM mytable ORDER BY random_record LIMIT 10" LIMIT 10 (or whatever number you want) limits the number of random results returned by any one query) |
|
#4
|
|||
|
|||
|
It works great, thanks!
![]() |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Wanted: random order of results from a SELECT query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|