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 2005 Forums
 Transact-SQL (2005)
 distinct taking too long?

Author  Topic 

sqlclarify
Yak Posting Veteran

56 Posts

Posted - 2009-02-01 : 18:00:57
Hello,

I have a query which works fine when I don't use distinct. But.. as soon as I add distinct to remove duplicate columns it runs for a loong time. Is there anyway to work around this? I am also trying to use group by instead (that is, group by all the columns) to remove duplicates but my query is still running. Any advice please?

Thanks! :)

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-01 : 23:02:02
Please Post your query so we can analyze.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-01 : 23:08:00
what does execution plan say? try and spot the bottleneck step.or else post the query with some sample data and explain what you're trying to do
Go to Top of Page

AvanthaSiriwardana
Yak Posting Veteran

78 Posts

Posted - 2009-02-02 : 00:23:18
send me the query. :)

Avantha Siriwardana
Beware of bugs in the above code; I have only proved it correct, not tried it.
(Donald Knuth)
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2009-02-02 : 00:33:59
I'd put money on that you're missing a join and your DISTINCT is a bodge to try and 'fix it'. I would not say DISTINCT is useless by any means, but I'm always suspect of this when I see it.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-02 : 00:37:33
or another guess will be that relationship b/w two tables on join amy be one to many and your attempt may be to return a single record from secnd table for each value of first, in which case DISTNCT doesnt help as it always tries to take distinct of entire field combination rather than one or two fields alone in select list
Go to Top of Page
   

- Advertisement -