By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tablename (`UnixTime` INTEGER, `JobID` INTEGER, `Status` VARCHAR(7), `Data` VARCHAR(3));
INSERT INTO tablename (`UnixTime`, `JobID`, `Status`, `Data`) VALUES
('1010', '1', 'start', '...'),
('1012', '1', 'running', '...'),
('1013', '2', 'start', '...'),
('1015', '1', 'ok', '...'),
('1016', '2', 'running', '...'),
('1017', '3', 'begin', '...'),
('1018', '2', 'error', '...'),
('1021', '3', 'running', '...'),
('1022', '4', 'start', '...'),
('1023', '5', 'start', '...');
SELECT *
FROM tablename
WHERE JobID IN (
SELECT JobID
FROM tablename
GROUP BY JobID
ORDER BY MAX(UnixTime) DESC LIMIT 3
)
ORDER BY UnixTime;
UnixTime | JobID | Status | Data |
---|---|---|---|
1017 | 3 | begin | ... |
1021 | 3 | running | ... |
1022 | 4 | start | ... |
1023 | 5 | start | ... |