Selection of the maximum value from the base and at the same time another field
Demir last edited by
Hello. There's a product base, it has fields.
price_currency♪ The maximum price is selected from the base
MAX(price)How to select the relevant value
price_currencythe same request?
UPD: The second request is undesirable because it's a very cumbersome request with the Joines and the big ones.
SELECT other_field, max_field FROM table ORDER BY max_field DESC LIMIT 1
Order the sorting of the field, which shall be the maximum, in reverse. And with help
limitYou only get one recording (just a claim).
If the field can be null, you can do it.
ORDER BY max_field DESC NULLS LAST
What do you do when there's not one thing to do?
The simplest option is to ignore all but one of the first ones:
But if it's not possible to ignore for any reason, try a request for sub-requests.
SELECT other_field, max_field FROM table t JOIN (SELECT MAX(max_field) max FROM table) m ON m.max = t.max_field
SELECT other_field, max_field FROM table WHERE max_field = (SELECT MAX(max_field) FROM table)
I don't know if there's anything else in place to simplify the task.