Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNION, INTERSECT, OUTER JOINS, or INNER JOINS?

Status
Not open for further replies.

ruse7013

Programmer
Apr 10, 2003
25
US
Oracle DB version: 8.1.7

Scenario:
---------
There are three tables A, B, and C. All of them have columns - c1, c2, and c3. Table A has about 30 million recods, table B - about 60 million records, and table C - about 1.5 million records.

Question:
---------
With one query, how can we retrieve all records (i.e., c1, c2, and c3) that belong either to table A, or B, but not in table C?

In other words, I need to find those records (columns c1,c2,c3) that belong to a DISTINCT record list based on tables A and B, but do not belong to table C.

Example:
--------

Table A Table B Table C
-------- -------- --------
c1 c2 c3 c1 c2 c3 c1 c2 c3
-------- -------- --------
a1 a2 a3 a1 a2 a3 b1 b2 b3
b1 b2 b3 b1 b2 b3 m1 m2 m3
p1 p2 p3

Based on the above example, record "a1 a2 a3" exists in tables A and B but not in table C. Also, record "p1 p2 p3" exists in A but not in C.

Is it possible to accomplish this with one query?

Thanks.
<ruse7013>
 
(SELECT c1, c2, c3
FROM Table A
UNION
SELECT c1, c2, c3
FROM Table B)
MINUS
SELECT c1, c2, c3
FROM Table C

This will have to work!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top