Easy MySQL solution
IntuitionTo solve this problem, we need to find the first year each product was sold and retrieve the corresponding sales data (quantity and price). The key ide
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
To solve this problem, we need to find the first year each product was sold and retrieve the corresponding sales data (quantity and price). The key idea is to:

1. Identify the earliest year (MIN(year)) for each product.

2. Use this information to filter the rows in the Sales table that match the first year of sales for each product.

# Approach
<!-- Describe your approach to solving the problem. -->
**1. Subquery to Find First Year:**
- Use a subquery to group the Sales table by product_id and calculate the minimum year (i.e., the first year) for each product.
- This subquery returns a list of (product_id, first_year) pairs.

**2. Filter Rows Using Subquery:**
- In the main query, use the WHERE (product_id, year) IN (...) clause to filter the rows in the Sales table.
- This ensures that only the rows where the year matches the first year of sales for each product are selected.

**3. Select Required Columns:**

- Select the product_id, year (aliased as first_year), quantity, and price from the filtered rows.

# *# Do upvote if you like the solution*

# Code
```mysql []
# 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);
```
['MySQL']