Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Using SELECT DISTINCT in SQL SERVER 2008

Author  Topic 

amit_18706
Starting Member

1 Post

Posted - 2014-05-08 : 04:26:20
Hello,

Recently one of our performance test was taking long time to run on the server and was getting timed out. When we applied "Select Distinct" to our query it started performing fine. Distinct generally removes duplicate records but query earlier was not returning any duplicate records either.

Can anyone explain how "SELECT DISTINCT" improved performance bcoz it generally is an overhead on the DB server. Are there any exceptional cases where use of DISTINCT really benefits?

Thanks




stepson
Aged Yak Warrior

545 Posts

Posted - 2014-05-08 : 04:44:59
I think that cause/trigger a recompile of your sp and now , the query plan is optimized for the current state


sabinWeb MCP
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2014-05-08 : 05:43:10
Sometimes DISTINCT in a CTE/Derived table etc that then gets joined to something else can improve performance, if a lot of duplicates are removed, as the join/subquery has less to do.
Go to Top of Page
   

- Advertisement -