Skip navigation links

MySQL Forums :: General :: search for query that result one random url from domain


Advanced Search

Re: search for query that result one random url from domain
Posted by: Rick James ()
Date: December 06, 2011 11:59PM

I don't know about speed, but this seems to work:
SELECT  url
    FROM  
      ( SELECT  url, domain
            FROM  tbl
            ORDER BY  RAND() ) y
    GROUP BY  domain
    ORDER BY  NULL
    LIMIT  1000;

Example:
mysql> SELECT city, state FROM
    -> ( SELECT city, state FROM us ORDER BY RAND() ) y
    -> GROUP BY state
    -> ORDER BY NULL
    -> LIMIT 11;
+-----------------+-------+
| city            | state |
+-----------------+-------+
| Gardiner        | ME    |
| Flossmoor       | IL    |
| Burke           | VA    |
| Sulphur Springs | TX    |
| Festus          | MO    |
| Garden Grove    | CA    |
| Bergenfield     | NJ    |
| Hanover         | MA    |
| Loudon          | NH    |
| Plymouth        | CT    |
| New Castle      | IN    |
+-----------------+-------+
11 rows in set (0.06 sec)

mysql> SELECT city, state FROM
    -> ( SELECT city, state FROM us ORDER BY RAND() ) y
    -> GROUP BY state
    -> ORDER BY NULL
    -> LIMIT 11;
+------------------+-------+
| city             | state |
+------------------+-------+
| Lyndon           | VT    |
| Mount Dora       | FL    |
| Memphis          | TN    |
| Grand Haven      | MI    |
| Georgetown       | DE    |
| Stanton          | CA    |
| Bismarck         | ND    |
| Valley Station   | KY    |
| Dracut           | MA    |
| Great Neck       | NY    |
| North Providence | RI    |
+------------------+-------+
11 rows in set (0.06 sec)

Options: ReplyQuote


Subject Written By Posted
search for query that result one random url from domain Bernd Meier 12/03/2011 07:52PM
Re: search for query that result one random url from domain Bernd Meier 12/04/2011 04:04PM
Re: search for query that result one random url from domain laptop alias 12/05/2011 05:39AM
Re: search for query that result one random url from domain Bernd Meier 12/05/2011 06:42AM
Re: search for query that result one random url from domain laptop alias 12/05/2011 07:55AM
Re: search for query that result one random url from domain Bernd Meier 12/05/2011 04:06PM
Re: search for query that result one random url from domain laptop alias 12/05/2011 06:28PM
Re: search for query that result one random url from domain Bernd Meier 12/05/2011 07:08PM
Re: search for query that result one random url from domain Rick James 12/06/2011 11:59PM
Re: search for query that result one random url from domain laptop alias 12/07/2011 03:24AM
Re: search for query that result one random url from domain Bernd Meier 12/08/2011 08:56PM
Re: search for query that result one random url from domain Rick James 12/08/2011 10:02PM
Re: search for query that result one random url from domain Bernd Meier 12/09/2011 05:31AM
Re: search for query that result one random url from domain laptop alias 12/09/2011 01:53AM
Re: search for query that result one random url from domain Bernd Meier 12/09/2011 04:42AM
Re: search for query that result one random url from domain laptop alias 12/09/2011 06:31AM
Re: search for query that result one random url from domain defor rest 12/09/2011 07:08AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.