You are here:
Retrieving and Segmenting Data with a SQL Query Activity
Retrieve and unify data across data extensions and system data views with SQL query activities. For example, you can prepare a subscriber list, view open and send history, or review automation and journey health.
A query activity is ideal for clean, structured datasets where audiences have already been created. If you want to unify and segment a large dataset, we recommend using your own internal data warehouse or an application such as Salesforce Customer Data Platform.
Planning Your SQL Query Activity
Consider the data that you want to collect and how you plan to use it. Review our query examples for ideas on how to get started.
Building Your SQL Query Activity
In Automation Studio, build a SQL query activity that retrieves the data that you’re interested in, and add it to an automation. Then optimize your query so that it doesn’t time out and fail.
Monitoring Query Health
Build SQL query activities and automations to review the health of all your automations, including SQL query activities. You can also set up email or Slack notifications for automation errors so that you can react quickly to failures.
Fixing Failed Queries
Understand why your query failed and then troubleshoot it. If the query timed out, optimize it.
Resources
There are other ways to retrieve data from Marketing Cloud Engagement, such as data extracts and API calls. If you want to unify and segment a large dataset, we recommend checking out Salesforce Customer Data Platform.
- Build a SQL Query Activity
In Automation Studio, build a SQL query activity that retrieves the data that you’re interested in, and then add it to an automation. - Optimizing a SQL Query Activity
SQL query activities time out after 30 minutes. You can prevent timeouts and failures by optimizing your SQL query activities. If your query consistently runs longer than 10 minutes, we recommend using a different tool, such as Salesforce Customer Data Platform, to transform your data. - Use Intermediate Tables to Optimize a Query
Split large queries into smaller components to use with Automation Studio’s query activity. - Data Views
Query system data views using Automation Studio for up to six months of Marketing Cloud Engagement subscriber and journey information. - SQL Query Examples
Learn how to build effective SQL queries in Automation Studio by following use cases. - SQL Reference
Get SQL query information for Automation Studio’s SQL Query activity at a glance. - Restart a Suspended SQL Query Activity
When a SQL Query activity encounters a system error or fails 24 consecutive times, we suspend it. To find out why your query is suspended, check the action log.

