views:

97

answers:

3
+2  Q: 

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.

+10  A: 
select Name, Object, max(Payment) as MaxPayment
from MyTable
group by Name, Object
RedFilter
Sorry...i made a change to my question. Good answer though. Sorry...im such a noob.
@user466334: I revised my answer accordingly.
RedFilter
Fastest gun ... SO is unfair and that is great news.
Hamish Grubijan
+4  A: 

Try:

SELECT Name, Object, MAX(Payment)
FROM   MyTable
GROUP BY Name, Object
p.campbell
+4  A: 
select Name, Object, max(Payment)
from table
group by Name, Object
Peter