Is there any purpose for using both DISTINCT and GROUP BY in SQL?
Below is a sample code
SELECT DISTINCT Actors FROM MovieDetails GROUP BY Actors
Does anyone know of any situations where both DISTINCT and GROUP BY need to be used, to get any specific desired results?
(The general usage of DISTINCT and GROUP BY separately is understood)
Perhaps not in the context that you have it, but you could use
SELECT DISTINCT col1, PERCENTILE_CONT(col2) WITHIN GROUP (ORDER BY col2) OVER (PARTITION BY col1), PERCENTILE_CONT(col2) WITHIN GROUP (ORDER BY col2) OVER (PARTITION BY col1, col3), FROM TableA
You would use this to return different levels of aggregation returned in a single row. The use case would be for when a single grouping would not suffice all of the aggregates needed.