Skip to main content

WHERE

Use WHERE to filter rows before aggregation. WHERE filters on dimensions, not metrics. To filter aggregated results, use HAVING. To set the reporting period for a query, use SINCE, UNTIL, DURING.

Wrap string values in single quotes. A WHERE condition can compare a column to a literal, check membership with IN, test inclusive ranges with BETWEEN, match strings or arrays with CONTAINS, combine conditions with AND or OR, or filter by related records with MATCHES.

Use the segment query language, a subset of ShopifyQL that uses only WHERE, to build customer segments from their attributes, save them in the Shopify admin, and query them through the GraphQL Admin API.

Note

Excluding values with !=, NOT IN, or NOT CONTAINS doesn't remove rows where the field is NULL. Add AND field IS NOT NULL to exclude rows with missing values.


Anchor to Comparison operatorsComparison operators

Compare a column or function result to a literal value. Equality works with any compatible scalar value. Ordered comparisons require ordered values such as numbers, money, dates, or text.

OptionSyntaxDescription
equals<column> = <value>Matches values equal to the right-hand side. Works with compatible scalar values.
not equals<column> != <value>Matches values not equal to the right-hand side. Works with compatible scalar values.
less than<column> < <value>Matches values less than the right-hand side. Use with ordered values such as numbers, money, dates, or text.
less than or equal<column> <= <value>Matches values less than or equal to the right-hand side. Use with ordered values such as numbers, money, dates, or text.
greater than<column> > <value>Matches values greater than the right-hand side. Use with ordered values such as numbers, money, dates, or text.
greater than or equal<column> >= <value>Matches values greater than or equal to the right-hand side. Use with ordered values such as numbers, money, dates, or text.

Anchor to Range and membership operatorsRange and membership operators

Match a value against a list, or test an inclusive range. Membership operators work with compatible scalar lists. Range operators require ordered values such as numbers, money, or dates.

OptionSyntaxDescription
IN<column> IN (<value>, ...)Matches any compatible value in a list.
NOT IN<column> NOT IN (<value>, ...)Excludes any compatible value in a list.
BETWEEN<column> BETWEEN <low> AND <high>Matches values within an inclusive range. Use with ordered values such as numbers, money, dates, or text.
NOT BETWEEN<column> NOT BETWEEN <low> AND <high>Matches values outside an inclusive range. Use with ordered values such as numbers, money, dates, or text.

Anchor to Null and Boolean checksNull and Boolean checks

Filter by missing values or Boolean states. Null checks work with any nullable field. Boolean checks work with Boolean values.

OptionSyntaxDescription
IS NULLIS NULLValue is null.
IS NOT NULLIS NOT NULLValue is not null.
IS TRUEIS TRUEValue is true.
IS NOT TRUEIS NOT TRUEValue is not true, including false or null.
IS FALSEIS FALSEValue is false.
IS NOT FALSEIS NOT FALSEValue is not false, including true or null.

Combine or negate conditions. AND is evaluated before OR, so group conditions with parentheses to control the order, for example WHERE a AND (b OR c).

OptionSyntaxDescription
AND<condition> AND <condition>Requires both conditions to match.
OR<condition> OR <condition>Requires either condition to match.
NOTNOT <condition>Negates a condition.

Filter string values by prefix, suffix, or substring.

OptionSyntaxDescription
STARTS WITH<column> STARTS WITH <value>Matches string-like values with the specified prefix.
ENDS WITH<column> ENDS WITH <value>Matches string-like values with the specified suffix.
CONTAINS<column> CONTAINS <value>Matches string-like values containing the specified substring, or arrays containing the specified element.
NOT CONTAINS<column> NOT CONTAINS <value>Matches string-like values or arrays that do not contain the specified value.

Check whether an array field contains a specific element with CONTAINS. The value you test must match the array's element type: use a string for a string array, a whole number for an integer array, or a decimal for a money array. Wrap string values in single quotes, and don't quote numeric or money values. String array matching is case-insensitive.


Filter by recurring annual dates, such as signup or first-purchase dates. anniversary() compares the month and day of a date or datetime field with =, !=, or BETWEEN.


Use MATCHES and NOT MATCHES to filter by collections of related records. A MATCHES filter keeps rows that have at least one related record matching the named parameters, joined by customer. A parameter can filter on a dimension or a metric. MATCHES is the only place you can filter by a metric in WHERE.

Note

Each parameter filters on a single field, and you can use each field only once in a MATCHES filter. Separate multiple fields with commas, not AND or OR.

You can use MATCHES when you query the following schemas. Each schema's reference lists the MATCHES expressions available when you query it:


Was this page helpful?