Skip to content
Advertisement

Find names based on max number dynamically in SQL

I have a data set like this:

Table A:

What’s the maximum number of Place on which a Partner has spent money and who are these Partners? Display only the Partners reaching this max number

I tried this:

But I feel like its not the right logic. What am I missing?

Advertisement

Answer

There’s really no need for your subquery, it works without it:

but it won’t make any difference to have one because of how queries are optimized, so whichever is easier to read is best. With a sub query it looks like this:

If you only want the name on the highest result(s) then you want to:

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