#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Posts
    6
    Rep 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...
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Posts
    6
    Rep 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?
  4. #3
  5. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    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)
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Posts
    6
    Rep Power
    0
    It works great, thanks!

Similar Threads

  1. modifying mysql query to refine results
    By jules00 in forum PHP Development
    Replies: 10
    Last Post: December 16th, 2003, 01:54 PM
  2. Replies: 12
    Last Post: December 6th, 2003, 07:31 PM
  3. MySQL desc order query solving problem
    By dssachdeva in forum MySQL Help
    Replies: 3
    Last Post: September 18th, 2003, 03:52 AM
  4. Replies: 5
    Last Post: September 13th, 2003, 10:16 PM
  5. Replies: 0
    Last Post: April 4th, 2002, 02:46 PM

IMN logo majestic logo threadwatch logo seochat tools logo