I know there are questions on the same topic, but I couldn't get it right.
I am following this link, and tried this query:
SELECT * FROM food_list f
INNER JOIN (
SELECT MAX(updated_on) max_row, rate, item_id
FROM food_rate
GROUP BY rate, item_id
) f_max ON (f_max.item_id = f.id)
INNER JOIN food_rate fr ON (fr.updated_on = f_max.max_row);
But I am not getting the records right.
Here's my table:
food_list:
id | item
----------------
1 | pizza
2 | burger
3 | sandwich
food_rate:
id | item_id | rate | updated_on
----------------------------------------------
1 | 1 | 80 | 2018-06-01
2 | 2 | 90 | 2018-06-01
3 | 3 | 70 | 2018-06-01
4 | 1 | 60 | 2018-06-02
I want to receive the records with latest date from food_rate for each item in food_list.
Here's the expected output:
item_id | rate | updated_on
----------------------------------
1 | 60 | 2018-06-02
2 | 90 | 2018-06-01
3 | 70 | 2018-06-01