I am looking for duplicate addresses on records where a foreign key differs. This gives me the duplicates:
select quoteID, insuredID, Address1, PolicyID
from quote
where
address1 in(select address1 from quote group by address1 having count(address1) > 1)
and datalength(address1) <> 0
order by address1
I want to filter out all records where the insuredID is the same. I really need to keep the quoteID in the results so I can investigate problem accounts. I am using SQL Server 2008.