Refining the row set
The WHERE clause is a boolean expression evaluated per row. Rows for which it evaluates true are kept; the rest are dropped.
The operators you'll use 95% of the time:
- Comparison:
=,!=/<>,<,<=,>,>=. - Boolean combinators:
AND,OR,NOT, parentheses for grouping. - Set membership:
IN (a, b, c),NOT IN (...). - Range:
BETWEEN a AND b(inclusive on both ends). - NULL:
IS NULL/IS NOT NULL— never= NULL(always false). - Pattern:
LIKE 'a%',GLOB,REGEXP(with extension).
Warning:
NULL = NULL is NULL, not TRUE. NULL != anything is also NULL. Always use IS NULL / IS NOT NULL. The number of bugs caused by forgetting this is staggering.