Question : TSQL Find Duplicates

Experts -- Please Help!!
I have a table with companies and states. I need to know if a company is in more than one state.
I want to ignore anything that is in only one state. This should be easy, but I can't seem to get it done.

Sample Data
COMPANY STATE
IBM              NE
IBM              DE
HP               NY

What I want returend (only companies residing in more than one state)

COMPANY STATE
IBM              NE
IBM              DE

Answer : TSQL Find Duplicates

SELECT DISTINCT COMPANY, STATE
FROM yourtablename as tblA
INNER JOIN
(SELECT COMPANY, STATE, COUNT(STATE) AS EntryCount,
FROM (SELECT DISTINCT COMPANY, STATE FROM yourtablename)
GROUP BY COMPANY
WHERE EntryCount <> 1) as tblB ON tblA.COMPANY = tblB.COMPANY

(Might have to count STATE, not COMPANY....) - slight change there.
Random Solutions  
 
programming4us programming4us