MySQL Select Row With Highest Column Value

QuestionsMySQL Select Row With Highest Column Value
sethbeckerman5 Staff asked 4 years ago

Given the data set for a table :

id
person
stock
invested

1
Jack
GOOG
1000

2
Jack
META
800

3
Jack
TSLA
1500

4
Jill
GOOG
4000

5
Jill
TSLA
1000

6
Taylor
WMT
1000

7
Taylor
TGT
2500

8
Taylor
HD
1000

I'm trying to figure out how to query and get the stock in which each person is most invested. In this example, I'm looking for this result:

id
person
stock
invested

3
Jack
TSLA
1500

4
Jill
GOOG
4000

7
Taylor
TGT
2500

I've been trying to work with something basic like this:

However, with a real data set, I'm not getting the expected results. What am I getting wrong?


View on Stack Overflow