Like that:
SELECT other_field, max_field FROM table ORDER BY max_field DESC LIMIT 1
Order the sorting by the field, which should be maximum, in the reverse order. And with the help of limit
get only one record (just the required one).
If the field can be null, then you can make ORDER BY max_field DESC NULLS LAST
At the request of viewers.
What to do when the goods with the maximum price is not one?
The easiest option is to ignore everyone except the one that came first :)
But if it is impossible to ignore for some reason, then try a query with sub-queries.
Such:
SELECT other_field, max_field FROM table t JOIN (SELECT MAX(max_field) max FROM table) m ON m.max = t.max_field
Or this:
SELECT other_field, max_field FROM table WHERE max_field = (SELECT MAX(max_field) FROM table)
I donβt know whether they invented anything else to simplify the task.
Select price_currency from table where price = (Select MAX(price) from table)
? - Alexey Shimansky.... and price = (Select MAX(price) from table)
? - Alexey Shimansky