MySQL Forums :: Newbie :: max function


Advanced Search

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 paul ernest 10/05/2009 11:49AM
Re: max function Tom Melly 10/05/2009 11:49AM
Re: max function paul ernest 10/05/2009 12:01PM
Re: max function Chad Bourque 10/05/2009 12:01PM
Re: max function paul ernest 10/05/2009 12:08PM
Re: max function Tom Melly 10/05/2009 12:12PM
Re: max function Rick James 10/06/2009 08:57PM
Re: max function laptop alias 10/07/2009 04:09AM
Re: max function Tom Melly 10/07/2009 05:06AM
Re: max function laptop alias 10/07/2009 05:48AM
Re: max function paul ernest 10/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.