469,333 Members | 4,661 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,333 developers. It's quick & easy.

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 4677
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.