---
schema_version: "1"
id: 1c5528d5ec2b8f761789a9a267df736048b82edc57f4c53c3f24b128d4cf4675
title: Build a SQL Query Activity
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/mktg/264-0-0/mc_as_use_the_sql_query_activity.md
canonical_url: https://help.salesforce.com/s/articleView?id=mktg.mc_as_use_the_sql_query_activity.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 4dae82abadc320152ceedece0bcbed00b64d9ca938414e3b825637e3bf7abb12
description: In Automation Studio, build a SQL query activity that retrieves the data that you’re interested in, and then add it to an automation.
products:
  - Marketing
  - Marketing Cloud Engagement
release: "264"
---
# 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.

Before you begin, [create a data extension](https://help.salesforce.com/s/articleView?id=mktg.mc_cab_create_a_new_data_extension.htm&language=en_US) to store the query results.

1. Click **Activities**.
2. Click **Create Activity**.
3. Select **SQL Query**.
4. Enter query properties, such as name, external key, and description.
5. Click **Next**.
6. Write a SQL query.
    
    - To see data extensions in your account that you can query, click a folder.
    - To add all columns from a data extension, double-click the data extension or drag it into the query. Remove the extra comma that appears after the final column name.
    - To add a single column, double-click the column name or drag it into the query. Remove the extra comma that appears after the column name.
    - You can’t include both a `JOIN` and a `SELECT *` statement. Instead, write a statement that specifies each column name, even when there are multiple columns.
    
    ![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_journeys_and_automations-264-0-0-production-enus/e08cdd71-c1c1-4ae5-a5e9-8a6dad583ad4/images/icon_important.png)
    
    Important Don’t enter column names manually, because the SQL query activity can’t identify the associated data extension. Always double-click or drag columns from the data extension list.
7. To test the query, click **Validate Syntax**.
8. Click **Next**.
9. Choose a target data extension to store the query results. The target can’t be a data extension that you used in the query.
10. Select how the query activity writes data to the target data extension.
    
    - Append—New data is added to the end of the target data extension. Existing data isn’t updated.
    - Update—Matching data in the target data extension is updated. New data without a match is added to the end of the target data extension.
    - Overwrite—All existing data is deleted from the target data extension and replaced with new data.
11. Save the activity.
12. Start or run the activity from the Activities page or include it in an automation.
    
    The query’s output is stored in the target data extension. You can view the results of each query’s run in the activity’s action log.