Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > select version(); > > <pre> > | version() | > | :-------------- | > | 10.3.32-MariaDB | > </pre> <!-- --> > 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'); > > <pre> > ✓ > > ✓ > </pre> <!-- --> > 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 > > <pre> > 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 > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=mariadb_10.3&fiddle=36b51459484827bb6a4c4e171a7ead52)*
back to fiddle