
SheldonLinker |
The method last shown will work, but is not the fastest. The following is:
DB2:
SELECT *
FROM firstTable a
EXCEPTION JOIN secondTable b ON
a.field=b.field
Oracle:
SELECT *
FROM firstTable AS a,
secondTable AS b
WHERE a.field=b.field(+) AND
b.field IS NULL
SQL Server:
SELECT *
FROM firstTable AS a
LEFT OUTER JOIN secondTable AS b ON
a.field=b.field
WHERE b.field IS NULL

jigarrshah |
select PI.*
from Product_Inf PI
left join Product_attribute_details PAD
on (PI.prod_key = PAD.prod_key)
where PI.prod_key is not null
or
select PI.*
from Product_Inf PI
where
not exists
(
select
‘x’
from
Product_attribute_details PAD
where PI.prod_key = PAD.prod_key and
PI.dye_class = PAD.dye_class and
PI.prod_range = PAD.prod_range
)

vikramnag |
I would not suggest a join here. Go with either the Exists or the IN clause.
Vikram Nag

jigarrshah |
sorry, it should be,
select PI.*
from Product_Inf PI
left join Product_attribute_details PAD
on (PI.prod_key = PAD.prod_key)
where PAD.prod_key is null

BeerMaker |
Hey, ilink88, since we’ve helped you out with your query. why don’t you satisfy our curiosity here and compare the performance of the Join and “Not IN” methods.
Use the show execution plan on Query Analyzer and post the results. Check your indexes, etc to see what you can do to make it fly.
Cheers