All Products
Search
Document Center

Time Series Database:WHERE clauses

Last Updated:Mar 28, 2026

Use a WHERE clause to filter data by field values, tag values, or timestamps.

Syntax

SELECT_clause FROM_clause WHERE <conditional_expression> [(AND|OR) <conditional_expression> [...]]

WHERE clauses accept conditional expressions on fields, tags, and timestamps, combined with AND and OR operators. Use parentheses to control operator precedence.

Fields

field_key <operator> ['string' | boolean | float | integer]

Field values can be strings, Booleans, floats, or integers.

Important

Always enclose string field values in single quotation marks ('). Queries with unquoted or double-quoted string values return no data and no error. See No results returned for examples.

Supported operators:

OperatorDescription
=Equal to
<>Not equal to
!=Not equal to
>Greater than
>=Greater than or equal to
<Less than
<=Less than or equal to

Arithmetic operators and regular expressions are also supported.

Tags

tag_key <operator> ['tag_value']
Important

Always enclose tag values in single quotation marks ('). Queries with unquoted or double-quoted tag values return no data and no error. See No results returned for examples.

Supported operators:

OperatorDescription
=Equal to
<>Not equal to
!=Not equal to

Regular expressions are also supported.

Timestamps

The default time range depends on the query type:

Query typeDefault time range
Most SELECT statements1677-09-21 00:12:43.145224194 UTC to 2262-04-11T23:47:16.854775806Z UTC
SELECT with GROUP BY time()1677-09-21 00:12:43.145224194 UTC to now()

For the full timestamp syntax, see the Time syntax topic.

Examples

Filter by a numeric field value

SELECT * FROM "h2o_feet" WHERE "water_level" > 8

Returns all data points in h2o_feet where water_level exceeds 8:

timelevel descriptionlocationwater_level
2015-08-18T00:00:00Zbetween 6 and 9 feetcoyote_creek8.12
2015-08-18T00:06:00Zbetween 6 and 9 feetcoyote_creek8.005
[...]
2015-09-18T00:12:00Zbetween 6 and 9 feetcoyote_creek8.189
2015-09-18T00:18:00Zbetween 6 and 9 feetcoyote_creek8.084

Filter by a string field value

SELECT * FROM "h2o_feet" WHERE "level description" = 'below 3 feet'

Returns all data points where level description equals below 3 feet. String field values must be in single quotation marks.

timelevel descriptionlocationwater_level
2015-08-18T00:00:00Zbelow 3 feetsanta_monica2.064
2015-08-18T00:06:00Zbelow 3 feetsanta_monica2.116
[...]
2015-09-18T14:06:00Zbelow 3 feetsanta_monica2.999
2015-09-18T14:36:00Zbelow 3 feetsanta_monica2.907

Filter using an arithmetic operator

SELECT * FROM "h2o_feet" WHERE "water_level" + 2 > 11.9

Returns data points where adding 2 to water_level exceeds 11.9. Standard arithmetic operator precedence applies. For details, see the InfluxQL arithmetic operators topic.

timelevel descriptionlocationwater_level
2015-08-29T07:06:00Zat or greater than 9 feetcoyote_creek9.902
2015-08-29T07:12:00Zat or greater than 9 feetcoyote_creek9.938
2015-08-29T07:18:00Zat or greater than 9 feetcoyote_creek9.957
2015-08-29T07:24:00Zat or greater than 9 feetcoyote_creek9.964
2015-08-29T07:30:00Zat or greater than 9 feetcoyote_creek9.954
2015-08-29T07:36:00Zat or greater than 9 feetcoyote_creek9.941
2015-08-29T07:42:00Zat or greater than 9 feetcoyote_creek9.925
2015-08-29T07:48:00Zat or greater than 9 feetcoyote_creek9.902
2015-09-02T23:30:00Zat or greater than 9 feetcoyote_creek9.902

Filter by a tag value

SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica'

Returns all data points where the location tag equals santa_monica. Tag values must be in single quotation marks.

timewater_level
2015-08-18T00:00:00Z2.064
2015-08-18T00:06:00Z2.116
[...]
2015-09-18T21:36:00Z5.066
2015-09-18T21:42:00Z4.938

Filter by field and tag values together

SELECT "water_level" FROM "h2o_feet" WHERE "location" <> 'santa_monica' AND ("water_level" < -0.59 OR "water_level" > 9.95)

Returns data points where location is not santa_monica and water_level is below -0.59 or above 9.95. Use parentheses to group OR conditions within an AND expression.

timewater_level
2015-08-29T07:18:00Z9.957
2015-08-29T07:24:00Z9.964
2015-08-29T07:30:00Z9.954
2015-08-29T14:30:00Z-0.61
2015-08-29T14:36:00Z-0.591
2015-08-30T15:18:00Z-0.594

Filter by timestamp

SELECT * FROM "h2o_feet" WHERE time > now() - 7d

Returns data points from h2o_feet with timestamps in the last seven days. For the full timestamp syntax, see the Time syntax topic.

FAQ

No results returned

If a query returns no results and no error, check that all string field values and tag values are enclosed in single quotation marks (').

Tag values:

SELECT "water_level" FROM "h2o_feet" WHERE "location" = santa_monica
SELECT "water_level" FROM "h2o_feet" WHERE "location" = "santa_monica"
SELECT "water_level" FROM "h2o_feet" WHERE "location" = 'santa_monica'

The first two queries return no data. The third, with single quotation marks, returns the expected results:

timewater_level
2015-08-18T00:00:00Z2.064
[...]
2015-09-18T21:42:00Z4.938

String field values:

SELECT "level description" FROM "h2o_feet" WHERE "level description" = at or greater than 9 feet
ERR: error parsing query: found than, expected ; at line 1, char 86
SELECT "level description" FROM "h2o_feet" WHERE "level description" = "at or greater than 9 feet"
SELECT "level description" FROM "h2o_feet" WHERE "level description" = 'at or greater than 9 feet'

Without quotes, a parse error is returned because the value contains spaces. With double quotation marks, the query runs but returns no data. With single quotation marks, the query returns the expected results:

timelevel description
2015-08-26T04:00:00Zat or greater than 9 feet
[...]
2015-09-15T22:42:00Zat or greater than 9 feet