Skip to content
Advertisement

Is it possible to use SELECT DISTINCT and GROUP BY together?

Is it possible to use SELECT DISTINCT and GROUP BY clause together? I need DISTINCT to avoid duplicate values and make a single entry of the records, and then get the Total quantity of those duplicate values.

For example, I have columns like Item Name and Quantity and their records are (product A,5), (product A,7).

Since products are the same I want it as a single entry and then total its quantity. So, the output on my report would be like this: (product A,12)

Can DISTINCT and GROUP BY clause solve this together?

Advertisement

Answer

Based on your comment on Used_By_Already’s answer, I think you need to use sum() over (…) construct, such as the following…

Which yields the result:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement