MySQL Forums
Forum List  »  Newbie

Re: max function
Posted by: Rick James
Date: October 06, 2009 08:57PM

SELECT *
    FROM
    (   SELECT product,
               price
            FROM Products
        ORDER BY price DESC
    ) AS x
    GROUP BY product;
This should get the top price for each product.

It uses the "feature" that GROUP BY picks the first row of each group. In this case, that is the highest priced item (because of ORDER BY price DESC). If two have the same price, it will pick one at 'random'.

Options: ReplyQuote


Subject
Written By
Posted
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
Re: max function
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.