Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple SQL Problem

Hey...I am in a bind here. I am not much of a programmer but the guy who does the sql at my business is out sick.

If I have a table like this (I am simplifying this a lot but this is where I am stuck).

Name Object   Payment

Joe  A         100
Jan  A         200
Joe  A         300
Ron  A         500
Jan  A         100
Joe  B         200

How do I write a query that would give me:

Joe A    300
Jan A    200
Ron A    500
Joe B    200

Essentially the highest value in the Payment field for each name. Thanks. Sorry if I sound dumb...but I just cant find anything on the internet to help me.

like image 707
user466334 Avatar asked Dec 30 '25 09:12

user466334


2 Answers

select Name, Object, max(Payment) as MaxPayment
from MyTable
group by Name, Object
like image 101
D'Arcy Rittich Avatar answered Jan 01 '26 23:01

D'Arcy Rittich


select Name, Object, max(Payment)
from table
group by Name, Object
like image 27
Peter Avatar answered Jan 02 '26 00:01

Peter