Database / SQLite Interview questions
What is a NULL value in SQLite?
NULL represents a missing or unknown value — it's distinct from an empty string
('') or zero (0), and it follows SQL's three-valued logic: comparing anything to
NULL using = yields NULL (neither true nor false), not
TRUE or FALSE.
SELECT * FROM person WHERE age = NULL; -- returns nothing; use IS NULL instead SELECT * FROM person WHERE age IS NULL; -- correct way to check for NULL
This is a common source of bugs for developers unfamiliar with SQL's NULL semantics: a straightforward
= NULL comparison never matches anything, since NULL isn't considered equal to
anything, including another NULL — the correct check is always
IS NULL or IS NOT NULL.
More Related questions...