Salesforce Marketing Cloud offers a robust set of tools for crafting targeted email campaigns. But what if you need to leverage the full potential of your Salesforce data to create even more precise audience segments? This is where SQL comes in.
SQL (Structured Query Language) empowers you to write custom queries and extract specific data points from your Salesforce database directly within Marketing Cloud. This unlocks a world of possibilities for personalizing your marketing efforts.
Today, we’ll use SQL to query a Salesforce database and identify email subscribers who opened a specific email campaign.
To get started, navigate to Automation Studio within Marketing Cloud. Here, you’ll utilize the SQL Query activity to write and execute your query. You can use Query Studio to see the results of your query before adding it to Automation Studio.
Here’s a sample SQL query that fetches subscribers who opened a specific email:
Query breakdown
SELECT DISTINCT
: Retrieves distinct values for each selected field, avoiding duplicates.- Joined tables:
[_Sent]
: Contains email send data.Contact_Salesforce
: Houses contact information from Salesforce.[_Job]
: Stores email job details like name and ID.[_Open]
: Captures email open activity.
- Filtering criteria:
o.SubscriberID IS NOT NULL
: Filters for subscribers who opened the email.con.Id IS NOT NULL
: Ensures contact information is available.s.JobID = '[...]'
: Targets a specific email job. This is the 6-digit “Job ID” number associated with each sent email.
- Retrieved fields:
- SubscriberKey, FirstName, LastName, Email
- EmailName (campaign name), JobID, SendDate
Applying the query
- Replace
[Job ID number]
with the actual ID of the email campaign you’re analyzing. - Paste the code into an SQL Query activity within Marketing Cloud’s Automation Studio.
- Choose a destination Data Extension to store the retrieved subscriber data.
- Validate the code and schedule the automation.
Key points
- Use
DISTINCT
to prevent duplicate records. - Join multiple tables to gather comprehensive information.
- Filter results using WHERE to target specific subscribers and campaigns.
- Validate code before execution.
- Select relevant fields to extract meaningful insights.