My table(products) looks like this:
id name value
1 oil 100
2 oil 140
3 glue 120
4 glue 110
I need to select last inserted oil and last inserted glue, so result should be:
2 oil 140
4 glue 110
what have i tried:
SELECT * FROM `products` GROUP BY `name` ORDER BY `value` DESC LIMIT 2
but this query shows
1 oil 100
3 glue 120
You need to get the last inserted row of each type (highest id), then retrieve the data for those ids. This assumes your id numbers go up with each new insertion, so a higher id value assumes a later insert.