Using Distinct or Not

Posted by RPS on Stack Overflow See other posts from Stack Overflow or by RPS
Published on 2010-06-04T14:04:21Z Indexed on 2010/06/14 20:32 UTC
Read the original article Hit count: 300

Filed under:

In the below SQL Statement, should I be using DISTINCT as I have a Group By in my Where Clause? Thoughts?

SELECT [OrderUser].OrderUserId, ISNULL(SUM(total.FileSize), 0), ISNULL(SUM(total.CompressedFileSize), 0)
FROM 
(
 SELECT DISTINCT ProductSize.OrderUserId, ProductSize.FileInfoId, 
 CAST(ProductSize.FileSize AS BIGINT) AS FileSize, 
 CAST(ProductSize.CompressedFileSize AS BIGINT) AS CompressedFileSize
 FROM ProductSize WITH (NOLOCK)
 INNER JOIN [Version] ON ProductSize.VersionId = [Version].VersionId
) AS total RIGHT OUTER JOIN [OrderUser] WITH (NOLOCK) ON total.OrderUserId = [OrderUser].OrderUserId
WHERE NOT ([OrderUser].isCustomer = 1 AND [OrderUser].isEndOrderUser = 0 OR [OrderUser].isLocation = 1) 
AND [OrderUser].OrderUserId = 1
GROUP BY [OrderUser].OrderUserId

© Stack Overflow or respective owner

Related posts about sql