Hi all,
I have the following table:
prod_name |
price |
year |
apple |
$1.00 |
2012 |
orange |
$1.00 |
2012 |
grape |
$1.00 |
2012 |
grape |
$2.00 |
2013 |
I need to write a query that will retrieve the records for each product using the most recent info (year). So the result of the query will look like this:
prod_name |
price |
year |
apple |
$1.00 |
2012 |
orange |
$1.00 |
2012 |
grape |
$2.00 |
2013 |
The query I have right now (below) retrieves everything and not just the latest year, it works if I just select the prod_name and year, but fails if I select all 3 fields (prod_name, price, year).
Here is my query:
Code:
SELECT prod_name, price, max(year) as max_of_year
FROM tbl_list
Group by prod_name, price;
Thanks!