TechMech
TechMech

Reputation: 170

mysql select combination of rows based on value

I have got an employee master table where I have field named 'Gender'. I want to select total 10 records from employee master table where I should get 5 records of Gender as Male and 5 records of Gender as Female. How can i do this?

Upvotes: 0

Views: 39

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172438

You can try like this:

select * from employee where Gender = 'Male' LIMIT 5
UNION ALL
select * from employee where Gender = 'Female' LIMIT 5;

Upvotes: 2

Related Questions