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.
I'd find out from them why. I cannot think of any reasons why "distinct"
is dangerous in some way.
IME, I've found that some people have usually had a bad experience with
doing something some particular way and won't do anything in that way
again and try to warn others away from it in a blind manner rather than
just finding out why something went wrong in the first place.
What was their proposal for the way you should be writing the same query
without using the distinct keyword?
Try analysing the execution plan of a query with and without the distinct
clause.
--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"?scar Martins" <subd...@hotmail.com> wrote in message
news:229f0a23.04080...@posting.google.com...
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)
DISTINCT usually forces a sort on the results so it's wise to avoid it where
it isn't necessary. It is also sometimes misunderstood that DISTINCT applies
to the whole result set. Sometimes people struggle to get the result they
want using DISTINCT when GROUP BY would give an easier solution.
--
David Portas
SQL Server MVP
--
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"?scar Martins" <subd...@hotmail.com> wrote in message
news:229f0a23.04080...@posting.google.com...
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
************************************************
Think Outside the Box!
************************************************
"?scar Martins" <subd...@hotmail.com> wrote in message
news:229f0a23.04080...@posting.google.com...
Or bad design that allows duplicates.
--
http://www.aspfaq.com/
(Reverse address to reply.)