Pankaj Mahato
Pankaj Mahato

Reputation: 1113

How select row where some column has more than 1 distinct value?

I have to find if there are Rows where a Name has more than one distinct Family.

Note: Name and Family can be duplicate.

ID      Name        Family
1       ABC         XYZ
2       DEF         XYZ
3       ABC         UVW
4       ABC         RST
5       DEF         RST
6       GHI         UVW

The expected Output should be

Name
ABC
DEF

Upvotes: 1

Views: 514

Answers (1)

James Cooke
James Cooke

Reputation: 1293

I think you could do this;

SELECT Name, COUNT(DISTINCT Family)
FROM [table]
GROUP BY Name
HAVING COUNT(DISTINCT Family) > 1

Upvotes: 1

Related Questions