Prepare the report input
Original presentation lists known estimates ascending, then unknowns, with id as tie order. SQLite ASC normally places NULL first. NULLS LAST implements the supplied display policy while preserving NULL. No work is assigned by this report.
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 | hours |
|---|---|
| A | NULL (unknown or absent) |
| B | 2 |
| C | 5 |
CREATE TABLE estimates(id TEXT PRIMARY KEY,hours INTEGER); INSERT INTO estimates VALUES('A',NULL),('B',2),('C',5);Compare misleading and corrected results
SELECT id,hours FROM estimates ORDER BY hours,id;| id | hours |
|---|---|
| A | NULL (unknown or absent) |
| B | 2 |
| C | 5 |
SELECT id,hours FROM estimates ORDER BY hours NULLS LAST,id;| id | hours |
|---|---|
| B | 2 |
| C | 5 |
| A | NULL (unknown or absent) |
Bad list starts unknown A; corrected list is B=2,C=5,A unknown. Unknown is not an observed zero-hour estimate.
Check a fresh boundary case
Make every estimate NULL. The output remains an all-unknown list ordered by id, not a claimed smallest known job.
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.
UPDATE estimates SET hours=NULL;
SELECT id,hours FROM estimates ORDER BY hours NULLS LAST,id;| id | hours |
|---|---|
| A | NULL (unknown or absent) |
| B | NULL (unknown or absent) |
| C | NULL (unknown or absent) |
Does the all-NULL boundary prove A takes least effort?
Show the worked answer
No. A is first only by the id tie rule; every effort value remains unknown.