About ShopifyQL
ShopifyQL is Shopify's commerce-focused query language that powers analytics and customer segmentation across the platform. Use ShopifyQL to build custom reports, analyze store performance, and gain insights from your merchant data.
Unlike general-purpose SQL, ShopifyQL abstracts away database complexity and provides built-in support for common commerce patterns like time-series analysis, currency handling, and multi-store reporting.
ShopifyQL enables you to:
- Query store data across sales, orders, products, customers, and sessions.
- Analyze trends with built-in time-series support and date range comparisons.
- Build visualizations directly within queries for charts and tables.
- Create customer segments using sophisticated filtering and matching patterns.
Anchor to How ShopifyQL worksHow ShopifyQL works
ShopifyQL queries follow a declarative structure where you specify what data you want rather than how to retrieve it. The language handles joins, aggregations, and data formatting automatically.
Anchor to Basic query structureBasic query structure
Every ShopifyQL query requires two keywords: FROM to specify the data source, and SHOW to select the metrics and dimensions to display:
ShopifyQL query
Anchor to Adding dimensions and filtersAdding dimensions and filters
Break down metrics by dimensions using GROUP BY, and filter results using WHERE:
ShopifyQL query
Anchor to Time-based analysisTime-based analysis
ShopifyQL provides powerful time-based filtering with SINCE, UNTIL, and DURING keywords:
ShopifyQL query
Compare periods using COMPARE TO:
ShopifyQL query
Anchor to Where you can use ShopifyQLWhere you can use ShopifyQL
ShopifyQL is available through multiple surfaces across Shopify:
Anchor to Key capabilitiesKey capabilities
Anchor to Data sourcesData sources
ShopifyQL supports querying from multiple data models:
| Table | Description |
|---|---|
sales | Transaction and revenue data. |
orders | Order information and fulfillment. |
products | Product catalog and inventory. |
customers | Customer profiles and segments. |
sessions | Storefront visitor sessions. |
Query multiple tables in a single query with implicit joins:
ShopifyQL query
Anchor to Time dimensionsTime dimensions
ShopifyQL abstracts date handling with built-in time dimensions:
| Dimension | Description |
|---|---|
second, minute, hour | Sub-day granularity. |
day, week, month, quarter, year | Calendar periods. |
hour_of_day, day_of_week | Cyclical time patterns. |
week_of_year, month_of_year | Annual patterns. |
Anchor to Named date rangesNamed date ranges
Use intuitive named ranges instead of calculating dates:
ShopifyQL query
Available named ranges include: today, yesterday, this_week, last_week, this_month, last_month, this_quarter, last_quarter, this_year, last_year, this_weekend, last_weekend, and bfcm{year}.
Anchor to VisualizationsVisualizations
Embed visualization instructions directly in queries:
ShopifyQL query
Supported visualization types:
- Charts:
bar,line,stacked_bar,stacked_area,donut,histogram - Tables:
table,list,list_with_dimension_values - Specialized:
funnel,heatmap
Anchor to Multi-store reportingMulti-store reporting
Organizations with multiple stores can query across their entire portfolio using FROM ORGANIZATION:
ShopifyQL query
Break down results by store using the shop_name dimension:
ShopifyQL query
Filter to specific stores using shop_id:
ShopifyQL query
Multi-store queries use the currency and timezone of the current store by default. Override these with WITH CURRENCY and WITH TIMEZONE:
ShopifyQL query
Anchor to TOP N analysisTOP N analysis
Control result cardinality with per-dimension limits:
ShopifyQL query
Use OVERALL for cross-dimension top items, and ONLY to exclude the "Other" bucket:
ShopifyQL query
Anchor to Common query patternsCommon query patterns
Anchor to Sales performance by periodSales performance by period
ShopifyQL query
Anchor to Top products with comparisonTop products with comparison
ShopifyQL query
Anchor to Regional breakdownRegional breakdown
ShopifyQL query
Anchor to Customer acquisition trendsCustomer acquisition trends
ShopifyQL query
Anchor to Product performance funnelProduct performance funnel
ShopifyQL query
Anchor to Best practicesBest practices
Anchor to Query optimizationQuery optimization
- Use appropriate date ranges: Narrow your
SINCE/UNTILrange to only the data you need. - Limit dimensions: Each
GROUP BYdimension increases query complexity. - Filter early: Apply
WHEREconditions to reduce the data set before aggregation. - Use
LIMIT: Restrict result sets, especially for exploration queries.
Anchor to Readable queriesReadable queries
- Use aliases: Give metrics descriptive names with
AS. - Format consistently: Place each keyword on its own line for complex queries.
- Add comments: Document complex logic with
--single-line or/* */block comments.
ShopifyQL query
Anchor to Next stepsNext steps
- Explore the ShopifyQL syntax reference for complete keyword documentation.
- Access the language reference for Shopify's segment query language.
- Get started with the ShopifyQL Python SDK for data analysis workflows.
- Learn about metafields and metaobjects for extending data models.