I have two database - Database1 and Database2.
Both database contain a table that have similar structure as follows:
=========================================================================================== | ID | Name | PhoneNoFormat | DialingCountryCode | InternationalDialingCode | InternetTLD | =========================================================================================== | | | | | | | ===========================================================================================
However, due to some reason, one of the tables in one of the database has data that is not exactly the same as the another table in the another database.
So, how can I compare Database1\Table1 against Database2\Table1?
I tried using query it but nothing happen so was wondering if I have write the wrong query.
SQL
SELECT MIN(TableName) as TableName,
ID,
Name,
PhoneNoFormat,
DialingCountryCode,
InternationalDialingCode,
InternetTLD
FROM
(
SELECT 'Table A' as TableName,
A.ID,
A.Name,
A.PhoneNoFormat,
A.DialingCountryCode,
A.InternationalDialingCode,
A.InternetTLD
FROM [D:\DATABASE1.MDF].[dbo].[Table1] AS A
UNION ALL
SELECT 'Table B' as TableName,
B.ID, B.Name,
B.PhoneNoFormat,
B.DialingCountryCode,
B.InternationalDialingCode,
B.InternetTLD
FROM [D:\DATABASE2.MDF].[dbo].[Table1] AS B
) tmp
GROUP BY ID, Name, PhoneNoFormat, DialingCountryCode, InternationalDialingCode, InternetTLD
HAVING COUNT(*) = 1
ORDER BY ID
