Re: Difference between = and IN
From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 02/07/05
- Next message: Hugo Kornelis: "Re: named transaction"
- Previous message: Hugo Kornelis: "Re: Cross Tab Query"
- In reply to: Andy: "Re: Difference between = and IN"
- Next in thread: Andy: "Re: Difference between = and IN"
- Reply: Andy: "Re: Difference between = and IN"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 07 Feb 2005 12:38:15 +0100
On Mon, 7 Feb 2005 02:21:01 -0800, Andy wrote:
>Thanks Steve
>So presumably if there is only one item it is more efficient
>to use = as the query processor does not need to convert it whereas the IN
>statement will be converted to = anyway?
>
>The main reason I am interested is that I am writing code that will build an
>SQL statement and wanted to know if I would be better off using an IN
>operator all the time or checking for instances where an = would suffice and
>using that instead.
>
>Thanks
>Andy
Hi Andy,
If you actually have to perform the subquery and count the number of rows
returned to choose between IN and =, then it's best to use IN, so that the
subquery is executed only once. If you have more efficient ways to
determine the number of rows returned, use =.
BTW, you might also consider using EXISTS instead of IN - it is generally
more efficient, but more important: NOT IN has very unpleasant behaviour
with NULLS and should be avoided (replace by NOT EXISTS); for uniformity,
I generally prefer to replace IN woth EXISTS as well. I use IN and NOT IN
only with a delimited list of values, never with a subquery.
Best, Hugo
-- (Remove _NO_ and _SPAM_ to get my e-mail address)
- Next message: Hugo Kornelis: "Re: named transaction"
- Previous message: Hugo Kornelis: "Re: Cross Tab Query"
- In reply to: Andy: "Re: Difference between = and IN"
- Next in thread: Andy: "Re: Difference between = and IN"
- Reply: Andy: "Re: Difference between = and IN"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|