Randomly selecting a limited number of records with two conditions in MySQL

Posted by andyashton on Stack Overflow See other posts from Stack Overflow or by andyashton
Published on 2009-10-21T16:01:08Z Indexed on 2010/04/27 14:43 UTC
Read the original article Hit count: 149

Filed under:
|

I have a MySQL table with a column called "priority". The column can have two values: high or low. I want to select 8 records from the table at random, but I want 6 of them to be high priority, and 2 of them to be low priority. If possibly, I would like to do it in one SQL statement. Is there any way to do two LIMITS in one query based on this kind of criteria?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql