I have the following table
CREATE TABLE TaskJournal (
TaskJournalId INT NOT NULL AUTO_INCREMENT,
TaskId INT NOT NULL,
TaskStatus TINYINT NOT NULL,
TaskStart INT NOT NULL,
TaskEnd INT NULL,
TaskInfo TEXT,
PRIMARY KEY (TaskJournalId)
) ENGINE = InnoDB;
INSERT INTO TaskJournal (TaskId, TaskStatus, TaskStart, TaskEnd, TaskInfo)
VALUES (2, 1, 1533660028, 1533660500, "No issues present"),
(3, 3, 1533660505, 1533660506, "Exception found: Line 95"),
(2, 1, 1533660015, 1533660018, "No issues present"),
(2, 3, 1533660509, 1533660512, "Exception found: Line 95"),
(2, 1, 1533660515, 1533660530, "No issues present");
The problem is this, I want to gather a list of errors but only if at a future time there is no resolution.
Ideally I'd get something like this back
| TaskJournalId | TaskId | TaskStatus | TaskStart | TaskEnd | TaskInfo |
| 3 | 2 | 1 | 1533660015 | 1533660018 | No issues present |
Only because in the future there isn't some TaskId that has the exception present.
So I thought I could do this via group of sub queries something like as follows:
SELECT *
FROM TaskJournal
WHERE TaskId = 2
GROUP BY TaskId, TaskStatus
HAVING TaskStatus=3
ORDER BY TaskStart DESC
But the problem with this is that it returns both rows 4 and 2 (chronological descending order). But at some later point there appears to have been a resolution to TaskId=2 but not for TaskId=3.
Any ideas would be helpful.