I was practicing this question on leetcode and I came up with the following solution:
select product_id, min(year) first_year, quantity, price from
Sales
group by product_id
But my above solution is wrong and the correct solution is:
-- # Write your MySQL query statement below
SELECT product_id, year AS first_year, quantity, price
FROM Sales
WHERE (product_id, year) in (
SELECT product_id, MIN(year)
FROM Sales
GROUP BY product_id
)
MY QUESTION:
Whats the difference between above two solutions, they look same to me but they give different results.