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 2000 Forums
 Transact-SQL (2000)
 count(distinct id) slower then nested query?

Author  Topic 

BorisCallens
Yak Posting Veteran

50 Posts

Posted - 2008-08-01 : 09:50:47
select count(distinct v.colorId) as totalCount
from searchView v
=> 5+ seconds

select count(t.kawnt) as totalCount
from (select distinct v.colorId as kawnt
from searchView v) as t
=> 1second

select distinct v.colorId
from searchView v
=> 1- seconds

Howcom does the extra complexity from the second query result in a faster query?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-01 : 13:14:06
have a had a look at query plans for first and second query?
Go to Top of Page
   

- Advertisement -