Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best way to exclude
Message
 
To
27/06/2011 09:23:18
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01516221
Message ID:
01516222
Views:
27
>Hi
>
>I'm extracting some records and I want to exclude some of them from being extracted.
>
>So I say
>
>SELECT * from member 
>where individual ref not in (select individual_ref from attribute where attribute.attr_code_ref = 1242 and individual_ref is not NULL and valid_to < getdate())
>
>Is that the best way of doing this. ?
>
>Thanks

You can find the best way if you turn Actual Execution plan on and test several different queries and check what is faster.
I prefer to write it with LEFT JOIN but this could be slower than yours, also the is NOT EXISTS() clause.
Check them all and choose faster :-).
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform