Select First Row In Each Group MySQL

Select the First Row In Each Group of MySQL

Here is an example:

      MIN(,  # change to MAX if you want the highest value
    PURCHASES purchases1
    JOIN (SELECT p.customer,
                 MAX(total) AS max_total
            FROM PURCHASES purchases
            GROUP BY p.customer) purchases2 
   ON purchases2.customer = purchases1.customer
      AND purchases2.max_total =
GROUP BY purchases1.customer,
Please follow and like us:
Content Protection by