where operator

where operator

Filters a table to the subset of rows that satisfy a predicate.

The where and filter operators are equivalent

Syntax

T | where Predicate

Parameters

NameTypeRequiredDescription
TstringTabular input whose records are to be filtered.
PredicatestringExpression that evaluates to a bool for each row in T.

Returns

Rows in T for which Predicate is true.

[!NOTE] All filtering functions return false when compared with null values. Use special null-aware functions to write queries that handle null values.

Performance tips

  • Use simple comparisons between column names and constants. ('Constant' means constant over the table - so now() is OK. ago() will be a specific function according to your database.

    For example, prefer where Timestamp >= minus(now(), toDayInterval(1d)) when using Clickhouse

  • Simplest terms first: If you have multiple clauses conjoined with and, put first the clauses that involve just one column. So Timestamp > ago(1d) and OpId == EventId is better than the other way around.

For more information, see the summary of available String operators and the summary of available Numerical operators.

Examples

Order comparisons by complexity

The following query returns storm records that report damaged property, are floods, and start and end in different places.

Notice that we put the comparison between two columns last, as the where operator can't use the index and forces a scan.

StormEvents
| project DamageProperty, EventType, BeginLocation, EndLocation
| where DamageProperty > 0
    and EventType == "Flood"
    and BeginLocation != EndLocation 

The following table only shows the top 10 results. To see the full output, run the query.

DamagePropertyEventTypeBeginLocationEndLocation
5000FloodFAYETTE CITY LOWBER
5000FloodMORRISVILLE WEST WAYNESBURG
10000FloodCOPELAND HARRIS GROVE
5000FloodGLENFORD MT PERRY
25000FloodEAST SENECA BUFFALO AIRPARK ARPT
20000FloodEBENEZER SLOAN
10000FloodBUEL CALHOUN
10000FloodGOODHOPE WEST MILFORD
5000FloodDUNKIRK FOREST
20000FloodFARMINGTON MANNINGTON