SQLite LEFT JOIN Filters: Keep Unmatched Assets in a Drone Inventory Review
Compare ON and WHERE filters in a small offline inventory example, preserve assets without a qualifying review, and explain why adding a NULL test is different.

Define which assets the review must retain
An inventory prepared alongside a drone mapping or inspection handoff may combine an asset table with a separate review table. A common requirement is to retain every asset while attaching only reviews with a selected status. A query can contain LEFT JOIN and still lose assets when a later filter removes the rows that represented unmatched records. Before investigating a disappearing identifier as a lost survey feature, inspect the complete query and state whether its intended result is all assets or only assets with qualifying reviews.
This tutorial uses three invented asset identifiers and two invented status records in a temporary SQLite database held in memory. It demonstrates attribute query behavior, without opening a GeoPackage, loading geometry, reading a customer inventory, or reporting an actual NiVO inspection. Asset A has an approved review, asset B has a pending review, and asset C has no review row. These three cases expose a difference that an example containing only approved matches would hide. The accompanying product photograph supplies context rather than evidence for these records.
Read the outer join and the later filter separately
The SQLite SELECT documentation describes LEFT JOIN as preserving unmatched left rows after its ON condition has been evaluated. Columns contributed by the unmatched right side are filled with NULL. The WHERE clause subsequently evaluates the resulting rows and retains only those for which its expression is true. An expression that evaluates to false or NULL removes its row. Consequently, putting a condition on a right-side status in WHERE can remove the very unmatched rows that motivated the outer join.
For the stated requirement, combine identifier equality and the approved-status condition inside ON. Asset B has no review that satisfies that combined condition, even though a pending review exists in the input table. It therefore receives a NULL right side, as asset C does. This does not assert that B and C have the same review history. It says that neither has a qualifying match in this particular result. Keep the original tables available when the distinction between pending evidence and no evidence matters.

Product context only; this photograph does not depict the constructed examples in this article.
Run three queries against the same small tables
Run the Python example locally. It creates a new in-memory connection, inserts the supplied teaching rows through bound parameters, runs three fixed SELECT statements, fetches their results, and closes the connection. No database file is opened or modified. The ON-filter result should contain A with approved status, followed by B and C with None in Python. The WHERE-filter result should contain only A. Ordering is explicit so that the comparison is about membership rather than incidental row order.
The third query tests a tempting workaround: leave the status condition in WHERE and add an alternative allowing a NULL right-side identifier. It returns A and C, but still loses B. In that query B already matched its pending review on identifier, so the join did not create an extra unmatched row for B. Its pending row then fails the WHERE expression. This is why an added NULL test does not reproduce filtering the candidate review rows inside ON. The printed results make that difference directly inspectable.
import sqlite3
def compare_joins(assets, reviews):
con = sqlite3.connect(":memory:")
try:
con.execute("CREATE TABLE asset(id TEXT PRIMARY KEY NOT NULL)")
con.execute("CREATE TABLE review(asset_id TEXT, status TEXT)")
con.executemany("INSERT INTO asset VALUES(?)", [(x,) for x in assets])
con.executemany("INSERT INTO review VALUES(?, ?)", reviews)
prefix = "SELECT a.id, r.status FROM asset AS a LEFT JOIN review AS r "
queries = {
"on": prefix + "ON a.id = r.asset_id AND r.status = ? ",
"where": prefix + "ON a.id = r.asset_id WHERE r.status = ? ",
"where_or_null": prefix + "ON a.id = r.asset_id "
"WHERE r.status = ? OR r.asset_id IS NULL ",
}
return {name: con.execute(sql + "ORDER BY a.id, r.status",
("approved",)).fetchall()
for name, sql in queries.items()}
finally:
con.close()
# Constructed attribute rows, not actual inspection records.
toy = compare_joins(["A", "B", "C"], [("A", "approved"), ("B", "pending")])
for name, rows in toy.items():
print(name, rows)Keep missing matches distinct from status conclusions
A NULL right side in the ON-filter result means that no supplied review row met the complete matching rule. It does not establish that an inspection was never attempted, that the asset is inaccessible, or that a flight failed. Those conclusions require their own evidence. Likewise, a selected status is just a stored value in this exercise; the query does not validate who assigned it or whether the underlying review is credible. Name the output columns and explain the selection condition alongside any exported inventory.
Avoid immediately replacing every NULL with a reassuring word such as complete or clear. A display label can be useful, but it should describe the query result accurately and preserve access to the original value. If a project needs separate categories for pending-only assets and assets with no review records, design and test an additional explicit query for those categories. The two NULL rows in this tutorial are intentionally sufficient for the all-assets-with-approved-matches requirement, rather than a complete review-history classification.
Check multiplicity before accepting the row count
LEFT JOIN preserves left-side membership under the stated conditions, but it does not promise exactly one output row per asset. If two approved review rows match A, both can appear. Counting output rows would then count joined combinations rather than unique assets. The teaching review table intentionally allows repeated identifiers so that this behavior remains visible. Before using a query result as an inventory total, compare both the identifiers represented and the number of matching records attached to each one.
A requirement for one review per asset needs a separate, documented selection rule. For example, a real workflow might define which revision is current, but a timestamp alone should not be invented or silently treated as authoritative. Do not add DISTINCT merely to conceal an unexplained one-to-many relationship. First inspect the review identity and the reason that multiple records qualify. This tutorial uses no spatial predicate, coordinate transformation, aggregation, or latest-record selection; it isolates filter placement so that those additional decisions remain explicit.
Extend the experiment by passing two approved rows for A and observe that A appears twice in each applicable result. Then pass an empty review list: the ON query retains every asset with an unmatched right side, while the status-only WHERE query returns no rows. Finally, try a review whose identifier is absent from the asset table. A left join does not add that right-only record to the inventory. These cases test the intended relationship rather than relying on one successful total.
Deliver the query and a membership comparison
For a real handoff, preserve the received dataset and record the exact input table versions, identifier columns, selected status, complete SQL, and SQLite version used for the check. Compare a few known assets covering approved, pending-only, and absent-review cases. Retain both the expected membership and the actual result. If a missing identifier is explained by WHERE placement, describe that query behavior specifically instead of claiming the original mapping data was repaired or that all inventory discrepancies have been resolved.
In a NiVO-related inventory discussion, this small experiment can distinguish an attribute selection problem from an unexplained loss of mapped assets. The useful result is a reproducible account of which rows the query retains and why. Keep geometry validity, survey acceptance, review quality, and operational conclusions with their independent evidence. Once the membership rule is agreed, verify it in the actual receiving application, whose query builder may generate additional clauses. Preserve that final SQL with the delivered result so another reviewer can repeat the same selection.



