MySQL Forums
Forum List  »  Newbie

LIMIT to Percent?
Posted by: Nathan Ziarek
Date: July 05, 2006 12:40PM

I have three queries, one to grab the most commented stories (LIMIT 10), one to grab the least commented stories (LIMIT 5), and on to grab the most recent stories (LIMIT 10). I am combining these using UNION to then randomly grab half of the resulting set. Is there a way to tell MySQL to "LIMIT 50%" or do I have to run it twice, once for the count and once with a limit?

So...

(SELECT * FROM blog WHERE...) UNION (SELECT * FROM blog WHERE...) UNION (SELECT * FROM blog WHERE...) ORDER BY RAND() LIMIT 50%

Thanks for any resources you can provide!

nate

Options: ReplyQuote


Subject
Written By
Posted
LIMIT to Percent?
July 05, 2006 12:40PM
July 05, 2006 12:47PM
July 05, 2006 01:20PM


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.