select key1 from table2
minus
select key1 from table1;
will show you if there any recodes exist in table1 but not in table2
Main Topics
Browse All TopicsHow to get the difference in records from two table.Tables are being formed from the queries.Tables are very big about 2 billion records each of them.We need the to find where the tables are same or different.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
First, I would perform a count on both tables. Assuming they are the same, you can
select * from table1
intersect
select * from table2
will give you all records that match between table 1 and 2. (on all columns). This should also be the same as the count from tables 1 and 2. If it is, everything is identical.
We should consider the fact of billions of records in each table. There are no rollback segment which would be enogh to make any of the above transactions.
I suppose the following can work:
1st) These tables should be PARTITIONed into as many as better parts. Use the same partitions.
2nd) Create in both tables an INDEX on an entire series of columns which you are going to compary.
The index columns should START with the PARTITIONing columns placed in the order of the partition
3rd) Add new indicating column (COMPATIBLE_ROWS_NO number) in both tables.
4th) Build a procedure which uses cursor for tableA with a hint of using the above index.
For each record:
FOR next_one IN <YOUR CURSOR> LOOP
a) UPDATE the indicating column of the 2nd table rows which "EQUAL" to the current row of the 1st table.
update tableB
set COMPATIBLE_ROWS_NO := nvl(COMPATIBLE_ROWS_NO,1)+
where <your comparision>;
!!! Assure using the above index in the update statement.
b) UPDATE the 1st table's indicating column using its ROWID -- do not deal with "WHERE CURRENT OF <your cursor>" !
update tableA
set COMPATIBLE_ROWS_NO = SQL%ROWCOUNT -- The number of compatible rows in the 2nd table
where rowid = next_one.ROW_ID;
5th) Do not forget commiting (COMMIT) each 10K records.
l_counter := nvl(l_counter,0)+1; if mod(l_counter,10000)=0 then commit; end if;
6th) As the result you should get your 1st table's indicating column
Hope it helps
Rather than using "minus," the following should work on any size data set:
Records missing from table1:
select * from table1 where not exists (select * from table2 where key = table1.key)
Records missing from table2:
select * from table2 where not exists (select * from table1 where key = table2.key)
..assuming you don't have too many differences. If you do, then you'll want to make the above statements cursors in a procedure and write each record to a table, committing every 10k records or so as alexfrl suggests. No need to do all the other complicated stuff he suggests, though.
Do your tables have primary keys? If not, none of the above solutions are guaranteed to work, because they will not account for duplicates. You'll have to do something like this:
SELECT Col1,Col2,...Coln,count(*)
FROM A
GROUP BY Col1,Col2,...Coln
MINUS
SELECT Col1,Col2,...Coln,count(*)
FROM B
GROUP BY Col1,Col2,...Coln
UNION ALL
SELECT Col1,Col2,...Coln,count(*)
FROM B
GROUP BY Col1,Col2,...Coln
MINUS
SELECT Col1,Col2,...Coln,count(*)
FROM A
GROUP BY Col1,Col2,...Coln
If size counts (like in your case), then you run this query several times with a WHERE clause added to restrict the number of rows in each comparison session.
select key1 from table1
minus
select key1 from table2;
will show you if there any recodes exist in table1 but not in table2
select key1 from table2
minus
select key1 from table1;
will show you if there any recodes exist in table1 but not in table2
select key1 from table1
intersect
select key1 from table2;
will get too much data.
You can also try:
select count(1) form
(select key1 from table1
intersect
select key1 from table2);
result should be the same as a count from table1 or table2.
There are going to be a lot of tunning issues involved like parallel execution, partitioning, using indexes (or not), using FFS of the index, etc.
Business Accounts
Answer for Membership
by: boriskalavskyPosted on 2004-11-17 at 00:17:22ID: 12601728
select key1 from table1
minus
select key1 from table2;
will show you if there any recodes exist in table1 but not in table2