Need help with my query for comparing two tables?!

J

juvi

Hello,

thx for any help in advance. I have got this query for comparing two tables
for differences. It works fine, but which changes must I do to only get the
query result from table B? I know that only table B can have changes so I do
not need the records from table A.

SELECT ID, COL1, COL2, COL3 ... INTO tbl_diff
FROM
(
SELECT A.ID, A.COL1, A.COL2, A.COL3, ...
FROM A
UNION ALL
SELECT B.ID, B.COL1, B.COl2, B.COL3, ...
FROM B
) tmp
GROUP BY ID, COL1, COL2, COL3 ...
HAVING COUNT(*) = 1
ORDER BY ID
 
J

John Spencer

Perhaps the following will work for you.

SELECT * FROM TableB Into tbl_Diff
WHERE TableB.Id in
(SELECT ID
FROM
(
SELECT A.ID, A.COL1, A.COL2, A.COL3, ...
FROM A
UNION ALL
SELECT B.ID, B.COL1, B.COl2, B.COL3, ...
FROM B
) tmp
GROUP BY ID, COL1, COL2, COL3 ...
HAVING COUNT(*) = 1)


John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top