Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL question
Why not simply
select A.col1, A.col2 from tableA A
minus
select B.col1, B.col2 from tableB B
or
select A.col1, A.col2 from tableA A
where (A.col1, A.col2) not in (
select /*+ hash_aj */ B.col1, B.col2 from tableB B
)
or
select A.col1, A.col2 from tableA A
where not exists (
select /*+ hash_aj */ null
from tableA A, tableB B
where A.col1 = B.col1
and A.col2 = b.col2
)
Which of these performs better depends on the sizes of the tables involved and the number of matches vs mismatches.
"Howard J. Rogers" <hjr_at_dizwell.com> wrote in news:3fa8270c$0$3504$afc38c87_at_news.optusnet.com.au:
>
> "Alex" <alexsm_at_eudoramail.com> wrote in message
> news:29ff93bc.0311041325.bcc6111_at_posting.google.com...
>> Hi ALL >> >> I've two tables and am trying to apply an OUTER JOIN on multiple >> fields. >> >> Table A has some rows as: >> >> <Table A> >> --- --- >> 1 a >> 1 b >> 2 b >> 3 a >> 3 c >> >> Table B is missing some of the rows. >> >> <Table B> >> --- --- >> 1 a >> 2 b >> 3 c >> >> >> Looking for only those rows Table B is missing: >> >> ---------- >> 1 b NULL >> 3 a NULL >> >> >> The following is not working: >> >> select t1.number, t1.letter, t2.number, t2.letter >> from TableA t1, TableB t2 >> where t1.number = (+)t2.number >> and t1.letter = (+)t2.letter
-- What lies behind us and what lies before us are small matters when compared to what lies within us. Wolfgang Breitling Oracle 7, 8, 8i, 9i OCPReceived on Tue Nov 04 2003 - 19:44:40 CST