Solved

ORACLE SLQ - Comparing records in 2 tables

Posted on 2008-06-13
6
956 Views
Last Modified: 2013-12-07
Table 2 retrieves data from existing fields in Table 1.  The system also creates additional fields in Table 2.  Not all fields are transfered from Table 1 to Table 2.  These tables may have millions of records so efficentcy is important.

I need to compare that the records are accurately populated in Table2 from Table1.  

              TABLE 1                                      TABLE 2
           Field1                                               Field1
           Field2                                               Field2
           Field3                                               Field3
           Field4                                            
           Field5                    
                                                                  Field6
                                                                  Field7
0
Comment
Question by:SharonInGeorgia
  • 2
6 Comments
 
LVL 29

Accepted Solution

by:
MikeOM_DBA earned 125 total points
ID: 21781371

SELECT * FROM TABLE1 A

 WHERE NOT EXISTS (

    SELECT '?' FROM TABLE2 B

     WHERE A.FIELDX = B.FIELDX );

Open in new window

0
 
LVL 32

Assisted Solution

by:awking00
awking00 earned 125 total points
ID: 21781470
The attached query compares every record in table1 OR table2 with every record in table1 AND table2. A perfect match will return no rows.

compare.txt
0
 

Author Comment

by:SharonInGeorgia
ID: 21782331
I understand that using UNION can be slow when dealing with massive amount of records.  What are your thoughts?
0
 
LVL 32

Expert Comment

by:awking00
ID: 21788752
In this case, I would probably use UNION ALL instead of UNION, which should avoid an extra sort, although the results are the same.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle Syntax 8 56
unable to get sorting resultset 15 68
Concat multi row values of a field in oracle 6 56
Oracle sql query 7 49
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now