Skip to content
Advertisement

How to do I query all distinct rows with only their highest values?

I have been trying to query each city’s popular genre. I am only trying to get the rows that I have highlighted. I tried using MAX() on a group by but gave me a syntax error.

My CTE query is as follows, its based on the dbeaver sample dataset:

I tried the following query.

Screenshot of query output

Advertisement

Answer

I don’t have a dataset to test this on, but you should be able to just add a ROW_NUMBER() function to your CTE to get the values you are looking for. Such as:

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