Dev Helpers

SQL / Projection and filtering

Filter on one status

Dev Helpers · July 31, 2025

A status filter is a useful baseline for a report. Explicitly decide how unknown or null statuses should behave.

Worked example

CREATE TABLE queues(name TEXT PRIMARY KEY, owner TEXT);
INSERT INTO queues VALUES
  ('build','platform'), ('assets','design'), ('reports','platform'), ('idle','ops');
CREATE TABLE jobs(id INTEGER PRIMARY KEY, name TEXT, queue TEXT, status TEXT, ms INTEGER, created TEXT);
INSERT INTO jobs VALUES
  (1,'compile-api','build','done',300,'2026-01-01 08:00'),
  (2,'test-api','build','done',500,'2026-01-01 09:00'),
  (3,'compile-css','assets','running',200,'2026-01-02 08:00'),
  (4,'test-css','assets','queued',NULL,'2026-01-02 09:00'),
  (5,'report','reports','done',100,'2026-01-03 10:00'),
  (6,'publish','build','queued',NULL,'2026-01-03 11:00');

SELECT name FROM jobs WHERE status='done';

Result

[
  {
    "name": "compile-api"
  },
  {
    "name": "test-api"
  },
  {
    "name": "report"
  }
]

Implementation notes

A status stored as text needs a stable vocabulary. An application rename should be coordinated with stored values and reports that filter them.

Try it yourself

Add an unrecognized status and check whether the report should surface it separately.

Open the SQL example →

Editorial date July 31, 2025 · Published December 6, 2026

Related articles

Alias a result column

An alias defines the name visible to query consumers. It can decouple an API field from a table's internal naming.

Select job names

Selecting named columns makes the result shape explicit. A later schema addition then leaves the consumer's expected fields intact.

Return unique queues

DISTINCT removes duplicate combinations across the entire selection. Adding another selected column can change what counts as unique.