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
 SQL Server Development (2000)
 DISTINCT v/s GROUP BY

Author  Topic 

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2006-09-01 : 01:39:00
can anybody tell me, what is the advantage of using DISTINCT over GROUP BY

Mahesh

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2006-09-01 : 02:25:33
GROUP BY lets you perform aggregates. DISTINCT simply gives you the results with no dupes.

Go to Top of Page

pootle_flump

1064 Posts

Posted - 2006-09-01 : 04:34:35
Distinct is intended to remove dupes. Group by can have the side effect of removing dupes but this is not what it is intended for. I would be surprised if the query plan differs for a simple, one table query. However I would expect use of group by to remove dupes in complex queries to have an overhead. Group by can tempt you into putting conditions into the having clause that really belong in the where clause too. If you need aggregates then, as timmy says, distinct is no use to you.

HTH
Go to Top of Page
   

- Advertisement -