NULL is a special marker defined by the SQL standard to denote the absence of any value in a column. It is not zero, not an empty string, and not the string "NULL". When a column contains NULL, it means the value is unknown, unavailable, or not applicable. SQL implements three-valued logic (TRUE, FALSE, UNKNOWN) to deal with NULLs, which affects comparisons, aggregates, and Boolean expressions.Key behaviors:- Comparisons with NULL using =, <, >, or <> return UNKNOWN, not TRUE/FALSE.- Use IS NULL or IS NOT NULL to test for NULL.- Aggregate functions (SUM, AVG, MAX, MIN) ignore NULLs, while COUNT(*) includes them.- Arithmetic or string operations that involve NULL generally return NULL.- Functions like COALESCE, NULLIF, ISNULL (SQL Server) and NVL (Oracle) provide ways to handle NULLs.Caveats:- NULLs can cause unexpected filtering and join results if not explicitly handled.- Unique constraints treat multiple NULLs as distinct in most dialects except SQL Server where only one NULL is allowed in a UNIQUE index (unless using a filtered index).
IS NULL, IS NOT NULL, COALESCE, NULLIF, NVL, ISNULL, NOT NULL constraint, three-valued logic
SQL-86 (ANSI X3.135-1986)
Comparing with = or <> returns UNKNOWN because NULL represents an unknown value. Use IS NULL or IS NOT NULL.
Wrap the column with COALESCE(col, fallback). SQL Server users can use ISNULL and Oracle users can use NVL.
Yes. COUNT(*) counts every row. COUNT(column) ignores rows where column is NULL.
No. An empty string has length zero while NULL means the value is unknown. Oracle is a notable exception where empty strings are treated as NULL.