Friday, February 24, 2012

IN() and duplicates

Does it matter to SQL if the IN() function has duplicates?This generates the same execution plan
USE pubs
SELECT * FROM authors
WHERE au_id
IN('172-32-1176','172-32-1176','172-32-1176','172-32-1176','213-46-8915')
SELECT * FROM authors
WHERE au_id IN('172-32-1176','213-46-8915')
Denis the SQL Menace
http://sqlservercode.blogspot.com/
Jayyde wrote:
> Does it matter to SQL if the IN() function has duplicates?|||Thanks :). I'm sure it's inefficient, but I'm guessing less so for SQL than
for me to take the time for C# to check for the duplicates.
-Jayyde
"SQL Menace" <denis.gobo@.gmail.com> wrote in message
news:1149689506.053562.310900@.i40g2000cwc.googlegroups.com...
> This generates the same execution plan
> USE pubs
> SELECT * FROM authors
> WHERE au_id
> IN('172-32-1176','172-32-1176','172-32-1176','172-32-1176','213-46-8915')
> SELECT * FROM authors
> WHERE au_id IN('172-32-1176','213-46-8915')
> Denis the SQL Menace
> http://sqlservercode.blogspot.com/
>
> Jayyde wrote:
>|||Unless the list is huge, generally it shouldn't matter. IN() implies
distinct elements even for subqueries.
Anith

No comments:

Post a Comment