Re: "distinct" keyword use in sql queries
From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 08/06/04
- Next message: fdde: "Re: "distinct" keyword use in sql queries"
- Previous message: Roji. P. Thomas: "Re: "distinct" keyword use in sql queries"
- In reply to: ?scar Martins: ""distinct" keyword use in sql queries"
- Next in thread: David Portas: "Re: "distinct" keyword use in sql queries"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 06 Aug 2004 12:04:12 +0200
On 6 Aug 2004 02:46:08 -0700, ?scar Martins wrote:
>Hi!
>
>Is there any kind of worry when using the keyword "distinct" in sql
>commands for querying DB Sqlserver 8??
>Some people higher experienced than me in vb.net apps development told
>me not to use "distinct" but they mentioned no reason for that...
>I´m struggling to not use "distinct"... Is that worth??
>
>thanks in advance.
Hi ?scar,
The one reason to avoid using DISTINCT when it's not needed is that it
decreases the query's performance. The usual technique for executing a
DISTINCT is sorting the intermediate results and then removing rows that
are equal to the row immediately before it. There are other techniques
that SQL Server's query optimizer will use if they appear to be cheaper,
but at the end of the day, looking for and filtering out duplicates will
always require extra work to be carried out by the DB. The performance hit
may vary between queries, but there will always be SOME impact.
Of course, if a query CAN give unwanted duplicates, you will need to
include DISTINCT or use another technique to get rid of duplicates, but I
agree that slapping DISTINCT onto every query "just in case" is bad
practice.
Best, Hugo
-- (Remove _NO_ and _SPAM_ to get my e-mail address)
- Next message: fdde: "Re: "distinct" keyword use in sql queries"
- Previous message: Roji. P. Thomas: "Re: "distinct" keyword use in sql queries"
- In reply to: ?scar Martins: ""distinct" keyword use in sql queries"
- Next in thread: David Portas: "Re: "distinct" keyword use in sql queries"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|