How to get rows with lowest value from a group by?

Discussion in 'MySQL' started by Mikkel Kjærgaard, Nov 1, 2021.

  1. Mikkel Kjærgaard

    Mikkel Kjærgaard New Member

    Oct 24, 2021
    Likes Received:
    Trophy Points:
    Hi Experts
    I have a database of beverages, with following tables:
    Beverage (code, name, size) Primary key=code
    Store (name, area, phone) Primary key=name
    Sells (store_name, code, price) store_name refers to name(store) and code to code(beverage).

    I need to find the code and name of the least expensive beverages for each store (1 value per store), but I am only able to find minimum price per store without the code via:
    SELECT store_name, MIN(price) FROM Sells GROUP BY store_name ORDER BY min(price)

    This gives me the store name and price of the least expensive beverages, but I need to somehow combine this with the Beverage table, so I get code and name also.
    Can anyone help me?

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice