MySQL Forums
Forum List  »  Newbie

max function
Posted by: paul ernest
Date: October 05, 2009 11:49AM

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

Options: ReplyQuote


Subject
Written By
Posted
max function
October 05, 2009 11:49AM
October 05, 2009 11:49AM
October 05, 2009 12:01PM
October 05, 2009 12:01PM
October 05, 2009 12:08PM
October 05, 2009 12:12PM
October 06, 2009 08:57PM
October 07, 2009 04:09AM
October 07, 2009 05:06AM
October 07, 2009 05:48AM
October 07, 2009 06:25AM


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.