Skip to main content

Syntax

Syntax is the set of clauses and parameters you write. Every query needs FROM, which chooses a table. A query must also select results with SHOW or VISUALIZE. Other clauses filter, group, and shape the result.

Use this reference to explore every clause and understand how to combine them into a query.


A query combines a table, result selection, and optional clauses that shape the result. FROM with SHOW makes a complete tabular query. If you omit SHOW, then the query must include VISUALIZE to select the metric it renders.

ShopifyQL requires FROM, but doesn't require the main clauses to be written in a fixed order. Unlike in SQL, you set a date range with SINCE, UNTIL, or DURING instead of WHERE.

FROM picks the table you want to query, like sales or customers. Each table's schema lists the metrics and dimensions you can use, and querying a field outside that schema returns a parse error.

SHOW lists the metrics you want returned as table columns, like total_sales or orders. VISUALIZE also names a metric, and renders it as a chart.

Anchor to Grouping, filters, and timeGrouping, filters, and time

Group results by dimensions like sales_channel, product_title, or month with GROUP BY, bucket them over time with TIMESERIES, or filter on them with WHERE. The dimensions you group by come back alongside your metrics.

Time clauses are optional, but pairing TIMESERIES with a date window (SINCE, UNTIL, or DURING) scopes the results to that window. For example, TIMESERIES day SINCE -30d.


Every query is a sequence of clauses. Square brackets mark optional parts, a slash or | separates alternatives, and [, ...] marks a part you can repeat.

Some syntax isn't tied to a single clause. Combine metrics from related tables in one query with a multi-fact query, or add comments to document a longer query.

FROM is required. A query also needs result selection from SHOW, VISUALIZE, or both, and you add only the other optional clauses your query needs.

ClauseRequired?What it does
FROMrequiredChooses the table, which determines the available metrics and dimensions.
SHOWconditionalLists the metrics and dimensions to return from the table. Required unless VISUALIZE selects a metric. Rename a field with AS.
WHEREoptionalFilters rows before grouping.
GROUP BYoptionalGroups results by one or more dimensions.
TIMESERIESoptionalBuckets results into a chartable time series.
WITHoptionalApplies modifiers like totals, percent change, and attribution.
HAVINGoptionalFilters grouped results.
SINCE, UNTIL, DURINGoptionalSets the reporting period.
COMPARE TOoptionalCompares the result against another period or target.
ORDER BYoptionalSorts results by one or more columns.
LIMIToptionalLimits the number of rows returned.
VISUALIZEconditionalRenders results as a chart and sets the type. Required when SHOW is omitted.
ANNOTATEoptionalOverlays contextual events on time-based charts.

These terms are used throughout the ShopifyQL reference. Some keywords take metrics, some take dimensions, and some take either. If you're not sure whether a field is a metric or a dimension, check the schema reference for the table you're querying. Each schema lists its metrics and dimensions separately.

TermDefinition
KeywordA reserved word that begins a clause, such as FROM, SHOW, or GROUP BY.
ClauseA keyword and the parameters that follow it, such as SHOW total_sales. A query is a sequence of clauses.
ParameterA value you pass to a clause, such as a table, column, condition, or date range.
OperatorA reserved word or symbol used within a condition, such as >=, STARTS WITH, or AND.
MetricA count or calculation that tracks a business indicator. Metrics are the columns you select with SHOW.
DimensionAn attribute you break metrics down by. Dimensions appear as columns, and their values define the rows.

Was this page helpful?