Nov 20, 2003 #1 NateUNI MIS Joined Jan 3, 2002 Messages 132 Location US I have the following query: SELECT * FROM Prospect WHERE Prospect.ID_NUMBER NOT IN ( SELECT ID_NUMBER FROM Prospect_EMAIL WHERE CAMPAIGNID=50) This query takes a LONG time to run. Is that a better way to write this query. I am using Oracle if that helps, Thanks!!
I have the following query: SELECT * FROM Prospect WHERE Prospect.ID_NUMBER NOT IN ( SELECT ID_NUMBER FROM Prospect_EMAIL WHERE CAMPAIGNID=50) This query takes a LONG time to run. Is that a better way to write this query. I am using Oracle if that helps, Thanks!!
Nov 20, 2003 #2 notadba MIS Joined May 28, 2003 Messages 154 Location AU Depending on which fields you need from the Prospect table, you could limit your query to just return the ID's by the following: SELECT ID_NUMBER FROM Prospect MINUS SELECT ID_NUMBER FROM Prospect_EMAIL WHERE CAMPAIGNID=50) Otherwise the Oracle forum might be a better place to get tuning info. Hope this hepls. Upvote 0 Downvote
Depending on which fields you need from the Prospect table, you could limit your query to just return the ID's by the following: SELECT ID_NUMBER FROM Prospect MINUS SELECT ID_NUMBER FROM Prospect_EMAIL WHERE CAMPAIGNID=50) Otherwise the Oracle forum might be a better place to get tuning info. Hope this hepls.
Nov 20, 2003 Thread starter #3 NateUNI MIS Joined Jan 3, 2002 Messages 132 Location US How about if I have fields in the first select that are not in the second select? Thanks! Upvote 0 Downvote
Nov 21, 2003 #4 dnoeth Instructor Joined Oct 16, 2002 Messages 545 Location DE SELECT * FROM Prospect p WHERE NOT EXISTS (SELECT ID_NUMBER FROM Prospect_EMAIL e WHERE p.ID_NUMBER = e.ID_NUMBER AND CAMPAIGNID=50) or SELECT p.* FROM Prospect p LEFT OUTER JOIN Prospect_EMAIL e ON p.ID_NUMBER = e.ID_NUMBER AND CAMPAIGNID=50 WHERE p.ID_NUMBER IS NULL I'm not shure if Oracle's Outer Join syntax using (*) will return the same result set. Dieter Upvote 0 Downvote
SELECT * FROM Prospect p WHERE NOT EXISTS (SELECT ID_NUMBER FROM Prospect_EMAIL e WHERE p.ID_NUMBER = e.ID_NUMBER AND CAMPAIGNID=50) or SELECT p.* FROM Prospect p LEFT OUTER JOIN Prospect_EMAIL e ON p.ID_NUMBER = e.ID_NUMBER AND CAMPAIGNID=50 WHERE p.ID_NUMBER IS NULL I'm not shure if Oracle's Outer Join syntax using (*) will return the same result set. Dieter