V
V
vista1x2015-03-18 15:56:33
SQL
vista1x, 2015-03-18 15:56:33

How to get row with maximum value of one field?

I have a query that returns the following data:

IDsumUserIDTaskID
2700982252356
27011002252356
27021002252356
2703562253356
27041002253356

It is necessary to select from this request (by another request) for each UserID and TaskID the maximums in the Sum field and return the entire line (with ID). If there are equal amounts, then return the last one. The result should be a table like this:
IDsumUserIDTaskID
27021002252356
27041002253356

The query seems to be simple, but there were problems with choosing the correct ID (it's not a primary key, but just a column returned by another query) for the maximum amount - I can't seem to select the one that corresponds to the desired maximum amount.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timofey, 2015-03-18
@vista1x

Directly you will not establish in any way to which ID the specific maximum Sum belongs. At least if the request contains GROUP BY UserID, TaskID.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question