Which Inspections Took Longer Than the Usual Visit?

Use one query’s result inside another without losing track of whether that result is one value, several rows, or a value belonging to the current asset.

13 sections · 4 questions · 1 coding challenge

1 / 13

A Query Could Supply Another Query’s Input

BOTIE

Once a question depends on a quantity calculated from stored records, a query language needs a way to compose those operations. SQL subqueries put a SELECT inside another statement. Modern SQLite and PostgreSQL document both independent subqueries and correlated ones whose values depend on an outer row.

Our inspection average is a small example of that composition. It keeps the calculation with the comparison, while leaving us responsible for the shape of the inner result and the meaning of missing values.

Sources for this history