Distinct and GROUP BY | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Distinct and GROUP BY

which one of the following query would perform better? 1) select distinct employeeid from Orders where ShipVia = 1 and CountryID = 840 2) select employeeid from Orders where ShipVia = 1 and CountryID = 840 group by employeeid while seeing the execution plan , both looks same. Table has 0.9 million records. could any one tell me which one would perform better? Thanks,
Ram "It is easy to write code for a spec and walk in water, provided, both are freezed…"
If the execution plan is the same, then the server will do exactly the same thing in both cases. So in an ideal world, the response time will be identical. If you run the two queries as a batch, you might see that the second one finishes faster – but that is only because of the data was loaded into cache when the first query was run. If you run the two queries again, you should see the same performance. You might also notice a difference in response time, but that will be due to external factors.
]]>