I have two views with an ID and an id_code field. (The underlying table is the same.) How can I select all the ID's from view 1 that are not present in view two?
The following code returns the ID's if it exists, but the opposite returns no data. I know that there is data that is in view 1 but not view 2.
select
AZ.AN_ID,
AZ.ZIP_CODE,
from
AUTHOR_ZIPCODE AZ
WHERE exists
(select AN_ID from
AUTHOR_ZIPCODE_DUPES AZD
)
(Please forgive double posting if it happens...I can't see the 1st post)
06-12-2002, 05:09 AM
nishant
Hi ,
select
AZ.AN_ID,
AZ.ZIP_CODE,
from
AUTHOR_ZIPCODE AZ
WHERE not exists
(select AZD.AN_ID from
AUTHOR_ZIPCODE_DUPES AZD
where AZ.AN_ID=AZD.AN_ID)
Hope it works....
06-12-2002, 05:35 AM
PFC
Is there another way? The performance is unacceptable for a small test table < 500 records. (I let it run for 20 minutes before killing it).
I can't imagine this on a real table with > 1 million records.
06-12-2002, 05:59 AM
bensr
How about this one:
select AN_ID
from
AUTHOR_ZIPCODE
minus
select AN_ID
from
AUTHOR_ZIPCODE_DUPES
06-12-2002, 06:49 AM
PFC
Great!
much more performant....this takes about 4 minutes on the table. I wish it would only take 2 minutes. :) Any more tips? ;)
06-12-2002, 11:21 AM
Mnemonical
from sql*plus:
WITH summary AS
(SELECT an_id FROM author_zipcode_dupes)
SELECT an_id FROM author_zipcode MINUS SELECT an_id FROM summary;