clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3799027 fiddles created (41853 in the last week).

select version();
version()
10.3.32-MariaDB
 hidden batch(es)


CREATE TABLE dataset ( `ItemID` INT, `ItemName` VARCHAR(10), `Value` INT, `Timestamp` TIMESTAMP ); INSERT INTO dataset VALUES ('1', 'A', '22', '2021-12-22 20:01:00'), ('1', 'A', '2', '2021-12-22 15:09:44'), ('1', 'A', '3', '2021-12-22 14:39:49'), ('2', 'B', '54', '2021-12-22 12:46:37'), ('2', 'B', '23', '2021-12-22 12:17:52'), ('2', 'B', '43', '2021-12-22 11:19:11'), ('1', 'A', '23', '2021-12-22 04:00:58'), ('1', 'A', '53', '2021-12-22 03:00:58'), ('3', 'C', '21', '2021-12-21 04:00:58'), ('2', 'B', '74', '2021-12-21 04:06:58'), ('2', 'B', '36', '2021-12-21 04:06:09'), ('1', 'A', '34', '2021-12-21 03:08:09');
 hidden batch(es)


WITH ordered AS ( SELECT *, LAG(`ItemID`) OVER (ORDER BY `Timestamp` DESC) AS LastItem FROM dataset ) SELECT `ItemID`, `ItemName`, `Value`, `Timestamp` FROM ordered WHERE `ItemID` <> `LastItem` OR `LastItem` IS NULL ORDER BY `Timestamp` DESC
ItemID ItemName Value Timestamp
1 A 22 2021-12-22 20:01:00
2 B 54 2021-12-22 12:46:37
1 A 23 2021-12-22 04:00:58
2 B 74 2021-12-21 04:06:58
3 C 21 2021-12-21 04:00:58
1 A 34 2021-12-21 03:08:09
 hidden batch(es)