Supppose I have a table called 'AnimalClass' that looks like this:
AnimalId | Gender | SocialID |
---|---|---|
1 | male | X001 |
1 | female | X2F8 |
1 | none | XGW7 |
2 | male | A902 |
2 | female | A2F5 |
2 | none | AGW6 |
3 | male | T0R3 |
3 | female | T2F0 |
3 | none | TGW1 |
I am looking for a query that would return only 'male' and 'female' genders that share a same Animalid category where the Socialid matches 'X2F8' OR 'A2F5'
Basically the result should be only male and female genders that share a matching Animalid and the Socialid of the female matches 'X2F8' OR 'A2F5':
AnimalId | Gender | SocialID |
---|---|---|
1 | male | X001 |
1 | female | X2F8 |
2 | male | A902 |
2 | female | A2F5 |
I've made a few attempts but I just can wrap my head around it:
SELECT * FROM AnimalClass
WHERE (Gender = 'male' OR Gender = 'female')
AND (SocialID = 'X2F8' OR SocialID = 'A2F5')
This query doesn't eventually give me results for both male and female but only for female.