MySQL Forums
Forum List  »  Optimizer & Parser

Re: ORDER BY RAND() taking too much time
Posted by: Ravenous Bugblatter Beast
Date: August 15, 2006 05:13PM

Try:

SELECT id, product_title, product_description, price_of_product, image_url FROM products WHERE id IN
(SELECT id FROM products WHERE products.id_pr_data_feed='some_id' ORDER BY RAND() LIMIT 12);

Although two selects, it will only have to random-sort a result set containing the ID column to pick the 12 rows rather than sorting the wider 5 column result set.

Options: Reply• Quote


Subject
Views
Written By
Posted
10728
April 29, 2006 05:30AM
Re: ORDER BY RAND() taking too much time
3635
August 15, 2006 05:13PM


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.