Let's say I have a payments table like so:
PaymentID INT, CustomerID INT, Value INT, PaidOn DATE
And I want to run a query for the maximum payment made by each customer. Is this possible using a single SQL query, to avoid having to dig through every row that I'm not interested -- or worse, run a query for each customer?
The best I have come up with so far is:
SELECT CustomerID, MAX(Value) FROM Payments GROUP BY CustomerID;
But this does not give me the PaymentId or PaidOn values for the rows it finds.