MySQL solution for beginners ✅✅ with explanation for why min(year) alone doesn't work
\n\n# Approach\nSELECT product_id, MIN(year) as first_year, quantity, price FROM Sales GROUP BY product_id) \nThis will not work as when you ask for the MIN yea
\n\n# Approach\nSELECT product_id, MIN(year) as first_year, quantity, price FROM Sales GROUP BY product_id) \nThis will not work as when you ask for the MIN year it will inspect each year from the pool and return it, but it will not select the entire row after returning the year.\n\nLet\'s say we have this input:\n\n| sale_id | product_id | year | quantity | price |\n| 1       | 400        | 2008 | 10       | 5000  |\n| 2       | 400        | 2009 | 12       | 5000  |\n| 3       | 400        | 2012 | 14       | 5500  |\n| 7       | 600        | 2012 | 15       | 9000  |\n\nIf we don\'t use the product_id, we end up with this result:\n\n| product_id | first_year | quantity | price |\n| 400        | 2008       | 10       | 5000  |\n| 400        | 2012       | 14       | 5500  |\n| 600        | 2012       | 15       | 9000  |\n\nFor more info refer this http://bernardoamc.github.io/sql/2015/05/04/group-by-non-aggregate-columns/ \n\n# Code\n```\n# Write your MySQL query statement below\nSELECT product_id, year as first_year, quantity, price \nfrom Sales \nwhere (product_id, year) in (\n        SELECT product_id, min(year) as year \n        from Sales \n        group by product_id \n        )\n```
['MySQL']