Solved

ORACLE SLQ - Comparing records in 2 tables

Posted on 2008-06-13
6
958 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.

829 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