Reputation: 1
I have a table participants where there are many fields such as name, sex, and etc. I need help finding duplicate names that have both sex's male and female.
SO if I have a name called 'Angel' and we have duplicate rows, how can we use a query to output 'Angel' being that there are lies 1 row rows that has sex = male and another row where the name is 'Angel' but the sex is female?
Upvotes: 0
Views: 101
Reputation: 521914
You can aggregate over records sharing the same name, and retain names whose distinct count of sex types is 2 (implying both genders are associated with that name).
SELECT name
FROM yourTable
GROUP BY name
HAVING COUNT(DISTINCT sex) = 2
Note that this assumes that only two genders exist in your table. If this be not the case, you can add a WHERE sex IN ('male', 'female')
clause to the above query.
Upvotes: 1