I have the following code
SELECT
PhysicalAddressID
FROM
tblPhysicalAddresses as a
WHERE EXISTS
(
SELECT
PhysicalAddressID
FROM
tblPhysicalAddresses as b
WHERE
a.PhysicalAddressID <> b.PhysicalAddressID AND
a.Address1 = b.Address1 AND
a.Address2 = b.Address2 AND
a.Address3 = b.Address3 AND
a.City = b.City AND
a.CountryID = b.CountryID AND
a.PersonID = b.PersonID AND
a.PhysicalAddressTypeID = b.PhysicalAddressTypeID AND
a.PostalCode = b.PostalCode AnD
a.Province = b.Province AND
a.StateID = b.StateID AND
a.ZipCode = b.ZipCode
)
I can visually look at the data and see that there are matches. However when I run the query it returns nothing. Could this be due to the comparison of nullable columns? If so what is the alternative. The goal is to find duplicate rows.
For example an instance where are of the columns are null. There is no match found although they are all null.
Basically I have 80 databases with the same schema. I decided to merge them into one. However there are duplicate addresses. Therefore my goal is to merge duplicate addresses.