I've got a query that, sometimes (based on user choice) I want to exclude 
rows in based on a matching ID being in a second table, a la

SELECT *
FROM Table1
WHERE ID NOT IN (SELECT ID From Table2)

or

WHERE NOT EXISTS (SELECT ID From Table2 WHERE ID = Table1.ID)

Either WHERE clause works fine. And these are very simplified examples.

Depending on the data, selecting without checking for matches is super 
fast, but checking against the matches can take an enormous amount of time 
in comparison. For example, with one situation I'm testing on (8700+ 
records, with just as many secondary matching records, except for two), 
selecting w/no matching exclusion takes 50ms. Selecting with the exclusion 
takes 73 seconds.

There's *got* to be a better way to do this...?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=6
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=6
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

                        

Reply via email to