LuísA
LuísA

Reputation: 59

How to identify different values in duplicate rows

Considering that i have the following table:

enter image description here

How i make a query that identify if the same code ( there can be duplicates, no problem with that at all ) have a diferent sex?

Example:

Code   Sex
1900   Male
1900   Female

I tried to do a little reseach before questioning here, but couldn't find the solution.

Thanks

Upvotes: 1

Views: 33

Answers (2)

Vasilis Vasileiou
Vasilis Vasileiou

Reputation: 527

If I understand correctly what you want is:

Select code, 
count(distinct sex) as val 
from table 
group by code 
having val>1

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269643

Here is one method:

select code
from t
group by code
having min(sex) <> max(sex);

Upvotes: 1

Related Questions