WHERE (pre-aggregation) and HAVING (post-aggregation) conditions. Both use the same operator set and can be combined with logical operators and groups.
WHERE vs HAVING
| Clause | When it runs | Use for |
|---|---|---|
WHERE | Before grouping and aggregation | Filtering raw rows |
HAVING | After grouping and aggregation | Filtering aggregated results |
Comparison operators
Import theOperator enum before using operators in the fluent API:
| Enum constant | Operator | Description |
|---|---|---|
EQUAL | = | Loose equality |
EQUAL_STRICT | == | Strict equality (type-safe) |
NOT_EQUAL | != | Loose inequality |
NOT_EQUAL_STRICT | !== | Strict inequality (type-safe) |
GREATER_THAN | > | Greater than |
GREATER_THAN_OR_EQUAL | >= | Greater than or equal |
LESS_THAN | < | Less than |
LESS_THAN_OR_EQUAL | <= | Less than or equal |
IN | IN | Field value is in the given array |
NOT_IN | NOT IN | Field value is not in the given array |
LIKE | LIKE | Pattern match — _ matches one character, % matches any sequence |
NOT_LIKE | NOT LIKE | Inverse of LIKE |
REGEXP | REGEXP | Match against a regular expression pattern |
NOT_REGEXP | NOT REGEXP | Inverse of REGEXP |
IS | IS | Type check — see IS operator section below |
NOT_IS | IS NOT | Inverse type check |
BETWEEN | BETWEEN | Field value is between two values (inclusive) |
NOT_BETWEEN | NOT BETWEEN | Inverse of BETWEEN |
Logical operators
Chain multiple conditions using logical operators:Basic examples
LIKE pattern matching
TheLIKE operator follows MySQL conventions:
| Wildcard | Matches |
|---|---|
% | Any sequence of characters (including empty) |
_ | Exactly one character |
REGEXP pattern matching
TheREGEXP operator accepts a regular expression pattern. If the pattern includes delimiters (e.g. /pattern/i), they are used as-is. Otherwise the pattern is wrapped in / delimiters automatically.
IS operator — type checking
TheIS and IS NOT operators check the PHP type of a field value. Pass a Type enum constant as the right-hand operand:
| Type constant | PHP type check |
|---|---|
Type::BOOLEAN | is_bool() |
Type::TRUE | === true |
Type::FALSE | === false |
Type::NUMBER | is_numeric() |
Type::INTEGER | is_integer() |
Type::FLOAT | is_float() |
Type::STRING | is_string() |
Type::NULL | is_null() |
Type::ARRAY | is_array() |
Type::OBJECT | is_object() |
Condition grouping
Group conditions withwhereGroup(), andGroup(), orGroup(), havingGroup(), and endGroup() to build complex logic. Use havingGroup() specifically to start a grouped condition within the HAVING context: