Key Takeaways
The specimen compares currently known blocked IDs and requires a non-null source ID. p.code IS NOT NULL with correlated NOT EXISTS returns A/Ana and C/Cy. Both the missing source ID and the blocklist NULL remain unresolved records; the two rows are a technical reference result, not proof of a complete list or approval to deliver it.
- The specimen’s NOT IN returns no rows; that does not establish that nobody meets the business rule.Read the supporting section: Run the failing query before blaming export
- NOT EXISTS checks matching rows; missing source IDs still need their own policy.Read the supporting section: A correlated query still needs a missing-ID policy
- Regress blocklists with NULL, without NULL and empty, checking row-level output.Read the supporting section: Accept the result set, not the explanation or indentation
In this article
Define what an acceptable exclusion result means
The query below is an editorial example of an AI-style mistake, not an output attributed to a particular model and not real personnel data. The source has A, B, C and one missing ID. The blocklist contains B and an unresolved NULL. The chosen rule is to deliver only known, nonblocked IDs.
The existing format-and-SQL semantics example examines LEFT JOIN conditions in ON versus WHERE. Here the defect is an unknown value in an exclusion subquery; rearranging formatting or join syntax alone is not the required fix.
The limited rule here compares confirmed, non-null blocked IDs only. The unresolved blocklist record still needs its source owner. If it could represent A or C, a final operational decision must wait for that clarification. A/C are results under the test rule, not proof that a real blocklist is complete or that release is approved.
Run the failing query before blaming export
The read-only CTE can run in a disposable SQLite test environment without creating or changing business tables. The editorial check used Python’s in-memory SQLite and returned zero rows for this fixed input. That is not the intended conclusion that no person is usable.
The SQLite expression reference specifies IN/NOT IN behaviour with NULL. A cannot be established as different from an unknown blocked ID, while B is explicitly blocked. Neither passes this WHERE condition.
WITH people(code, name) AS (
VALUES ('A','Ana'), ('B','Bo'), ('C','Cy'), (NULL,'Review')
), blocked(code) AS (VALUES ('B'), (NULL))
SELECT p.code, p.name FROM people p
WHERE p.code NOT IN (SELECT code FROM blocked)
ORDER BY p.name;A correlated query still needs a missing-ID policy
The repaired query returns A/Ana and C/Cy. The correlation b.code=p.code checks for an explicit blocked match; IS NOT NULL enforces this article’s source-ID requirement. Without that guard, NOT EXISTS also retains the missing-ID Review row, which violates the chosen delivery rule.
The PostgreSQL subquery reference explains the row-existence interpretation of EXISTS. The execution evidence here is SQLite, not a test of every database. Repeat the boundary cases under the actual dialect, types and constraints before adopting the query.
WITH people(code, name) AS (
VALUES ('A','Ana'), ('B','Bo'), ('C','Cy'), (NULL,'Review')
), blocked(code) AS (VALUES ('B'), (NULL))
SELECT p.code, p.name FROM people p
WHERE p.code IS NOT NULL
AND NOT EXISTS (SELECT 1 FROM blocked b WHERE b.code = p.code)
ORDER BY p.name;| Source ID | Name | Decision |
|---|---|---|
| A | Ana | Retain |
| B | Bo | Explicit blocked match |
| C | Cy | Retain |
| NULL | Review | Missing ID; review separately |
Accept the result set, not the explanation or indentation
Add two regressions: remove NULL from the blocklist and confirm A/C remain the known-ID result; make the blocklist empty and confirm A/B/C remain, with the missing source ID still isolated by the stated rule. Preserve unknown values instead of inventing a sentinel identifier.
Use the SQL formatter if indentation needs review, but that tool does not execute database queries. Save source, formatted text and actual database output separately. A structurally valid AI answer still needs the source-evidence checks for meaning.
Further reading & sources
Put the guide into practice
Open the relevant tool, preview the result and check your exported file.


