Reputation: 297
I have a database scheme with a table like this:
id --- username --- sex
1 A 1
2 D 2
3 F 1
4 G 2
5 H 1
6 x 1
7 r 1
I want to select only 2 males and lets say 4 females, male is 1 and female is 2. How would we achieve that in one mysql query and if I have more var's to select by ?
Upvotes: 0
Views: 27
Reputation: 204924
(select * from your_table where sex = 1 limit 2)
union all
(select * from your_table where sex = 2 limit 4)
Upvotes: 2