Distinct random rows

Reply

Join Date: Jan 2009
Posts: 3
Reputation: finance-blog is an unknown quantity at this point 
Solved Threads: 0
finance-blog finance-blog is offline Offline
Newbie Poster

Distinct random rows

 
0
  #1
Jan 4th, 2009
I have a query that gets 5 random values out of a table according to a query. i.e.

  1. SELECT * FROM links WHERE url contra = FALSE ORDER BY RAND() LIMIT 0,5

This is fairly simplified but you get the idea. One of the fields in the table is ip, how can I do that same but ensure that all the ip values are DISTINCT. Any ideas anybody?
Last edited by peter_budo; Jan 6th, 2009 at 9:28 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: Distinct random rows

 
0
  #2
Jan 9th, 2009
Originally Posted by finance-blog View Post
I have a query that gets 5 random values out of a table according to a query. i.e.

  1. SELECT * FROM links WHERE url contra = FALSE ORDER BY RAND() LIMIT 0,5

This is fairly simplified but you get the idea. One of the fields in the table is ip, how can I do that same but ensure that all the ip values are DISTINCT. Any ideas anybody?
Would this do the trick?

  1. SELECT DISTINCT ip, * FROM links WHERE url contra = FALSE ORDER BY RAND() LIMIT 0,5
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC