Get differences between two tables

G

Guest

I have two tables and I need to get a third table with the differences :

Table 1
---------
Field1 :-> A
Field2 :-> AAA
Field3 :-> Old table
B BBB Old table
C CCC Old table

Table 2
---------
Fied1 :-> A
Field2 :-> AAA
Field3 :-> New Table
B BBB New table
D DDD New Table

Table 3 should have the difference in this way
 
G

Guest

Try the following:

Select T1.Field1, T1.Field2, T1.Field3
FROM Table1 T1
LEFT JOIN Table2 T2
ON T1.Field1 = T2.Field1 AND T1.Field2 = T2.Field2
WHERE T2.Field3 IS NULL
UNION ALL
Select T2.Field1, T2.Field2, T2.Field3
FROM Table1 T2
LEFT JOIN Table1 T2
ON T2.Field1 = T1.Field1 AND T2.Field2 = T1.Field2
WHERE T1.Field3 IS NULL


Hope this helps

Dale
 
G

Guest

it is perfect. I just need to now to implement this solutions to the real
tables that are much more complicated than the below ones. Thanks
 

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

Similar Threads


Top