2

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.

user466334
  • 65
  • 3

3 Answers3

10
select Name, Object, max(Payment) as MaxPayment
from MyTable
group by Name, Object
D'Arcy Rittich
  • 167,292
  • 40
  • 290
  • 283
4

Try:

SELECT Name, Object, MAX(Payment)
FROM   MyTable
GROUP BY Name, Object
p.campbell
  • 98,673
  • 67
  • 256
  • 322
4
select Name, Object, max(Payment)
from table
group by Name, Object
Peter
  • 12,541
  • 3
  • 34
  • 39