i am using mysql8 server. Have such table and want to receive 1 last row for each good_id.
CREATE TABLE good_states (`ID` int, `good_id` int, `sales` int);
INSERT INTO good_states (`id`, `good_id`, `sales`)
VALUES
(1, 25, 33),
(2, 25, 34),
(3, 24, 14),
(4, 25, 64),
(5, 24, 53),
(6, 24, 457),
(7, 35, 96)
;
http://www.sqlfiddle.com/#!9/735bb60/1
This query
SELECT * FROM good_states WHERE `good_id` IN (25,24) GROUP BY good_id
return to me first row from good_states for each good_id, but i need to receive last row for each good_id.
3 | 24 | 14
1 | 25 | 33
I want to receive something like this
6 | 24 | 427
4 | 25 | 64
ORDER by id DESC - just don't work here. As GROUP BY sort answer in ASC way. Any way to do what i want without GROUP by?