MySQL Forums
Forum List  »  Newbie

Re: How does group by algorithm works?
Posted by: Rick James
Date: June 11, 2009 11:40PM

But, you can make it work with some extra effort:
select item, supplier, price as cheapest_price
   from (
      select item, supplier, price
         from products
         order by item asc, price asc
        )
   group by item ;

This is because the value of 'supplier' is not really arbitrary; it is actually the 'first' value found. Hence, you have to put the ORDER BY in the inner query, and let the ordering deal with the MIN().

Options: ReplyQuote




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.