Prepare the report input
Original queue requires active AND either urgent or overdue. AND binds more tightly than OR, so the ungrouped filter makes active apply only to overdue. Parentheses express the supplied scope.
Every record and report rule below is original and fictional. Reproduce the setup in a fresh SQLite test database; input previews include every table in this small fixture.
| id | urgent | overdue | active |
|---|---|---|---|
| A | 1 | 0 | 0 |
| B | 0 | 1 | 1 |
| C | 0 | 0 | 1 |
CREATE TABLE work(id TEXT PRIMARY KEY,urgent INTEGER CHECK(urgent IN(0,1)),overdue INTEGER CHECK(overdue IN(0,1)),active INTEGER CHECK(active IN(0,1))); INSERT INTO work VALUES('A',1,0,0),('B',0,1,1),('C',0,0,1);Compare misleading and corrected results
SELECT id FROM work WHERE urgent=1 OR overdue=1 AND active=1 ORDER BY id;| id |
|---|
| A |
| B |
SELECT id FROM work WHERE (urgent=1 OR overdue=1) AND active=1 ORDER BY id;| id |
|---|
| B |
A is urgent but inactive and must leave the queue. B is active and overdue and remains. The correction changes the predicate grouping, not any stored flags.
Check a fresh boundary case
Add active urgent D. It qualifies through the urgent branch while satisfying the shared active requirement.
Recreate the original setup in another fresh database, then apply the change and corrected query below. For an empty result, the table displays a labelled empty-result marker rather than a data record.
INSERT INTO work VALUES('D',1,0,1);
SELECT id FROM work WHERE (urgent=1 OR overdue=1) AND active=1 ORDER BY id;| id |
|---|
| B |
| D |
Why does A fail but D pass?
Show the worked answer
Both are urgent; only D is active. Shared active scope excludes A.