✅ Simple solution using only CTE ✅
\n\n# Approach\n Describe your approach to solving the problem. \nFirst prepared the temp table that has the MIN year for the particular product_id (GROUP BY).\
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst prepared the temp table that has the MIN year for the particular product_id (GROUP BY).\n\nThen by using this record, fetched the desired rows from Sales table.\n\nNOTE : No need for JOIN here, because we don\'t need to show the product_name from the Product table, If required in future we can join both table with product_id.\n\n# Code\n```postgresql []\n-- Write your PostgreSQL query statement below\nWITH temp as (SELECT product_id, MIN(year) as first_year FROM Sales GROUP BY product_id)\n\nSELECT s.product_id,s.year as first_year, s.quantity,s.price \nFROM Sales s \nWHERE (s.product_id,s.year) IN (SELECT product_id,first_year FROM temp)\n```
['PostgreSQL']