472,127 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

How to compare the contents of two tables of identical structure?

1
How to compare the contents of two tables of identical structure?
May 3 '07 #1
1 4721
frozenmist
179 Expert 100+
Hi,
You can use the union and minus .
Union gives those those which are in both the tables.
Eg:
(select * from table1) Union (Select * from table2)
TABLE1 TABLE2 RESULT
------------ ------------ ---------------
1 2 1
2 3 2
3

If you use the minus, u can get those rows in one table which are not in the other.
eg:
(select * from table1) minus (select * from table2)
will give result set as 1
(select * from table1) minus (select * from table2) gives 3

If you take the union of the two queries above you will get those rows which are only in one of the two tables
i.e;
((select * from table1) minus (select * from table2))
UNION
((select * from table1) minus (select * from table2))
gives 1and 3

Hope this was what you needed..
Cheers
May 3 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Kiran B. | last post: by
50 posts views Thread by titan nyquist | last post: by
3 posts views Thread by =?Utf-8?B?UmljY2FyZG8=?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.