Just a day ago, I was was asked this question in one of the teaching session to my team members. One of the member asked me if I can use DISTINCT in Aggregate Function and does it make any difference. The quick answer is yes, and a small example of DISTINCT in Aggregate Functions shows why.
Of course! It does make difference. DISTINCT can be used to return unique rows from a result set and it can be used to force unique column values within an aggregate function.
USE AdventureWorks
GO
SELECT SUM(DISTINCT ReorderPoint) ResultDistinct
FROM Production.Product
GO
SELECT SUM(ReorderPoint) ResultNoDistinct
FROM Production.Product
GO

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.





2 Comments. Leave new
Its very urgent..
I have a table called Permissions. in that I have iParentID, iPermissionID there….if I give the iParentId=1, suppose this record having the iPermissionId s 6,7,8. I need to display hirarchy wise…
can anyone help me regarding this