I have a table orderswith fields id, customer_idand amt:
SQL Fiddle
And I want to get customer_idwith the greatest amt and value of this amt.
I made a request:
SELECT customer_id, MAX(amt) FROM orders;
But the result of this query contained the wrong value customer_id.
Then I built a query like this:
SELECT customer_id, MAX(amt) AS maximum FROM orders GROUP BY customer_id ORDER BY maximum DESC LIMIT 1;
and got the correct result.
But I do not understand why my first request did not work properly . What am I doing wrong?
And is it possible to change my second request in order to get the necessary information for me in a simpler and more competent way?
source
share