I have a table for items purchased in different dates and would like to select only the latest date of each item. But when I use this code:
SELECT `pid`,`price`, MAX(`date`) FROM `products_purchase` GROUP BY `pid`
id pid price date 1 6 2.50 2015-12-8 2 6 2.65 2015-11-23 3 6 3.11 2015-10-14
I have looked at many solutions for "mysql max(date) not working" but finally noticed that it select the right date but wrong row it shows the price from other row. For example it shows date as 2015-12-8 (which is max date) but price of 2.65 which is from other row. Please help.