max function
I'm sorry to have to ask such a basic question here, but between google and web tutorials I can find an answer.
If I have a table with the columns product and price, how do I find the maximum price in the column AND the product which goes with it. I know that I can use max to find the maximum value in price, with
SELECT MAX(price) from Products;
but when I do
SELECT product,MAX(price) from Products;
I get a the correct result for the maximum price, but not the corresponding product, I just get the first product as they were entered in the table, eg
mysql> SELECT product,MAX(price) FROM products;
+------------+--------------+
| product | MAX(price) |
+------------+--------------+
| 0000673064 | 108.34 |
+------------+--------------+
in this case 108.34 is the maximum price in the table, but the product id 0000673064 does not correspond to that price.
Thanks
Subject
Written By
Posted
max function
October 05, 2009 11:49AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.