NiVO / BY TECHNOGISGermany · Indonesia
Inventory comparison tutorial

SQLite NOT IN and NULL: Explain an Empty Drone Inventory Difference Report

Compare NOT IN, correlated NOT EXISTS, and an explicitly filtered subquery in a small offline inventory, keeping missing identifiers separate from matching decisions.

SQLite NOT IN and NULL: Explain an Empty Drone Inventory Difference Report

Define the difference report before trusting an empty result

An inventory comparison in a drone mapping or inspection handoff may ask which candidate asset identifiers are absent from a supplied list. An empty SQL result can look reassuring, but it can also reflect the query treatment of missing identifiers. In particular, a NULL in the right-hand input of NOT IN can prevent unmatched candidates from satisfying the filter. Before interpreting an empty report as proof that every asset was delivered, inspect the actual query, its input columns, and the policy for unknown values.

This tutorial uses invented candidate identifiers A, B, and C, with a supplied list containing A and one missing identifier. The candidate column is explicitly non-null. Three queries compare their behavior on the same in-memory tables, without opening a GeoPackage or a customer inventory. The example explains attribute membership only. It does not establish that any real mapped asset is absent, that an inspection was completed, or that NiVO software produces this particular schema. The catalogue photograph supplies separate product context rather than evidence for the teaching records.

Read the documented NULL case for NOT IN

The SQLite expression documentation gives a result matrix for IN and NOT IN. For a non-null left value that is not found on the right, a nonempty right input containing NULL produces NULL rather than true for NOT IN. The SELECT documentation separately states that WHERE retains true expressions and excludes false or NULL expressions. In this constructed case, B and C therefore do not survive the raw NOT IN filter, even though neither has a matching non-null supplied identifier.

A is excluded for a different reason: its value is found in the supplied list. Keep those reasons separate when explaining why the raw query returns no rows. SQL NULL represents a missing or unknown value in this example, rather than an ordinary identifier string. A literal text value spelling NULL is another value entirely. Do not replace missing identifiers with a convenient text token before comparing inventories unless the project explicitly defines that transformation and documents how collisions with real identifiers are prevented.

NiVO VTOL V7 with a white fuselage, lift rotors, and yellow wing tips
NiVO VTOL V7 with a white fuselage, lift rotors, and yellow wing tips.Source: NiVO / TechnoGIS catalogue materials supplied by the site owner · Catalogue photo
Product context only; this photograph does not depict the constructed examples in this article.

Run three explicit comparisons against one toy inventory

Run the following Python function locally. It creates new in-memory tables, inserts values through bound parameters, and returns ordered results from three fixed queries before closing the connection. The first uses raw NOT IN. The second uses correlated NOT EXISTS to ask whether an equal identifier is present. The third uses NOT IN after explicitly removing NULL values from the supplied subquery. No source file is opened or modified. Ordering is included so the comparison concerns membership rather than incidental output order.

The raw result should be empty, while both other queries should return B and C for this stated non-null candidate profile. The filtered query embodies an explicit decision to exclude missing supplied identifiers from its membership list. The correlated query asks about equality matches without treating a missing supplied value as an equal identifier. Neither query repairs the missing record or establishes what it should have contained. Preserve that separate data-quality finding instead of hiding it merely because a clearer comparison query now returns useful candidates.

import sqlite3

def compare_missing_ids(candidates, supplied):
    con = sqlite3.connect(":memory:")
    try:
        con.execute("CREATE TABLE candidate(id TEXT PRIMARY KEY NOT NULL)")
        con.execute("CREATE TABLE supplied(id TEXT)")
        con.executemany("INSERT INTO candidate VALUES(?)", [(x,) for x in candidates])
        con.executemany("INSERT INTO supplied VALUES(?)", [(x,) for x in supplied])
        queries = {
            "not_in": "SELECT id FROM candidate WHERE id NOT IN (SELECT id FROM supplied)",
            "not_exists": "SELECT c.id FROM candidate AS c WHERE NOT EXISTS "
                "(SELECT 1 FROM supplied AS s WHERE s.id = c.id)",
            "filtered_not_in": "SELECT id FROM candidate WHERE id NOT IN "
                "(SELECT id FROM supplied WHERE id IS NOT NULL)",
        }
        return {name: [row[0] for row in con.execute(sql + " ORDER BY 1")]
                for name, sql in queries.items()}
    finally:
        con.close()

# Constructed attribute identifiers, not actual delivery records.
print(compare_missing_ids(["A", "B", "C"], ["A", None]))

Keep the left-side identifier policy visible

The comparison above deliberately requires candidate identifiers to be non-null. That condition matters when discussing the relationship between filtered NOT IN and NOT EXISTS. Do not generalize the example into a blanket claim that every query rewrite has identical behavior for nullable inputs. If a real candidate table permits missing identifiers, decide how those records should be represented and reviewed before choosing a membership query. Retaining an unknown asset identifier and declaring it absent from another list are different decisions that require an explicit policy.

The teaching candidate primary key also prevents duplicate candidate identifiers, while the supplied table permits duplicates. Repeated supplied matches do not create additional candidate rows in these predicates, but that observation does not validate the inventory identity rules. Check types, collation, whitespace, and the intended identifier representation in the actual workflow. A text code with leading zeros should not be silently converted merely to make two lists appear to agree. The function makes no normalization, coercion policy, latest-record choice, geometry join, or spatial comparison claim.

Test empty and incomplete supplied lists independently

Test an empty supplied table as a separate case. SQLite documents that NOT IN over an empty right input is true, so all non-null candidate identifiers in this example should be returned. Then test a supplied table containing only NULL: the raw NOT IN query should return no candidates, while the other two return all of them under the stated policy. Those outcomes are different from an input list containing every candidate identifier. A useful test set needs to distinguish these situations rather than relying on one plausible total.

Also test repeated supplied identifiers and an identifier that does not exist among the candidates. Keep the original inputs available and compare membership with the expected small set. A successful query does not prove that the supplied inventory is complete or that its missing values are acceptable. It establishes which candidate IDs satisfy the stated predicate. Any claim about absent survey evidence, delivery completeness, or review status needs the relevant project records and acceptance method, rather than being inferred from a SQL result alone.

Deliver the comparison rule with its unresolved records

For a real handoff, record the unchanged input identities, selected tables and columns, candidate nullability, missing-value policy, complete SQL, SQLite version, and expected small comparison set. Retain both the unmatched candidate output and a separate account of missing supplied identifiers. If the original empty result was caused by NULL-sensitive NOT IN behavior, describe that specific query interpretation. Do not report the inventory as repaired or accepted merely because a revised predicate expresses the intended comparison more clearly.

In a NiVO-related inventory discussion, this small experiment helps distinguish an empty comparison result from evidence that all mapped assets are present. Another reviewer can rerun the exact queries and see why the right-hand NULL changes one result. Continue independent checks for identifier quality, geometry, source completeness, and project acceptance through the appropriate workflow. The useful outcome is a reproducible membership rule with its assumptions attached, while unknown records remain visible for the people who can resolve their actual meaning.

If a query builder or receiving application generates SQL on the reviewer behalf, retain the final generated statement rather than only a screenshot of its filters. An added condition or a changed input column can alter the result even when the interface looks similar. Compare a known matched identifier, a known unmatched identifier, and an unknown supplied value after any change. This makes the check repeatable without claiming that the teaching schema or query performance represents a real production system.

Technical references

  1. SQLite expressions: IN/NOT IN result matrix and EXISTS ↗
  2. SQLite SELECT: WHERE removes false and NULL results ↗
  3. Python sqlite3: in-memory connections and parameterized statements ↗
← All articles

Related articles

All articles ↗
LET’S TAKE FLIGHT

Your next mission
starts with a conversation.

Talk to our team