Steven Duncan Steven Duncan - 6 months ago 9
SQL Question

SQL: How to get Max of Variable (per category of another varialbe)

I am a beginner in SQL and could really use some help.

Situation: I have a table containing the data field

my_number
and
my_location
(among many other data fields). I'm only concerned about those two fields. I want to select the maximum '
my_number
' for each '
my_location
'. There are only 3 possible my_location options but numerous possible my_number. All variables represented by numbers.

I was researching correlated subquery but I do not know how to use them. Maybe joins could work?
I am trying to learn different ways, effective ways to complete this task.

Answer

Try this:

SELECT 
     MAX(my_number) as Max_Number,
     my_location
FROM 
     TABLE
GROUP BY 
     my_location
Comments