SunQuest
           MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old June 25th, 2000, 07:19 AM
Johan Larsson Johan Larsson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 1999
Posts: 6 Johan Larsson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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...

Reply With Quote
  #2  
Old June 25th, 2000, 07:44 AM
Johan Larsson Johan Larsson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 1999
Posts: 6 Johan Larsson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #3  
Old June 25th, 2000, 10:59 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Pembroke Pines, Florida, USA
Posts: 2,300 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 3 h 2 m 4 sec
Reputation Power: 44
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)

Reply With Quote
  #4  
Old June 26th, 2000, 03:24 AM
Johan Larsson Johan Larsson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 1999
Posts: 6 Johan Larsson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It works great, thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Wanted: random order of results from a SELECT query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway