%(LIKE OPERATOR) - Use Cases
% is used for pattern matching (Partial Text Search)
Source DE:
1. Find Gmail Users:
SQL Query: Select *
From [Source DE_Like Operator]
Where EmailAddress LIKE '%@gmail.com'
Target DE:
2. Users whose name starts with 'A'
SQL Query: Select *
From [Source DE_Like Operator]
Where FirstName LIKE 'A%'
Target DE:
3. Users whose name ends with 'Kumar'
SQL Query: Select *
From [Source DE_Like Operator]
Where LastName Like '%Kumar'
Target DE:
4. Find users with 'Sale' in email (Campaing Filtering)
SQL Query: Select *
From [Source DE_Like Operator]
Where Emailaddress LIKE '%Sale%'
Target DE:
5. Find customers with cities contacining "Pur"
SQL Query: Select *
From [Source DE_Like Operator]
Where City LIKE '%pur%'
Target DE:
6. Target users with mobile number starting with "9"
SQL Query: Select *
From [Source DE_Like Operator]
Where PhoneNumber LIKE '9%'
Target DE:
7. Filter product names containing "Bottle"
SQL Query: Select *
From [Source DE_Like Operator]
Where ProductName LIKE '%Bottle%'
Target DE:
8. Journey Re-entry check (Email pattern)
SQL Query: Select *
From [Source DE_Like Operator]
Where EmailName LIKE '%Welcome%'
Target DE:
9. Identify Test Records:
SQL Query: Select *
From [Source DE_Like Operator]
Where EmailAddress LIKE '%test%'
Target DE:
10. Domain-Based Segmentation:
SQL Query: Select *
From [Source DE_Like Operator]
Where EmailAddress LIKE '%@yahoo.com'
Target DE:
Not/Exclusion Logic
In SQL, -Itself is subtraction, but in SFMC context, people mean Not/Exclusion Logic (very common in segmentation)
Question: Difference between Not Like & !=
Can we not use two Where syntax in the same automation?
11. Exclude Gmail Users:
SQL Query: Select *
From [Source DE_Like Operator]
Where EmailAddress NOT LIKE '%@gmail.com'
Target DE:
12. Exclude Unsubscribed Users:
SQL Query: Select *
From [Source DE_Like Operator]
Where Status NOT LIKE '%Active%'
From [Source DE_Like Operator]
Where Status != 'Unsubscribed'
Target DE
13. Remove Bounced Emails:
SQL Query: Select *
From [Source DE_Like Operator]
Where BounceCount = 0
Target DE:
14. Exclude Test Data:
SQL Query: Select *
From [Source DE_Like Operator]
Where EmailAddress NOT LIKE '%Test%'
Target DE:
15. Exclude Specific Domain:
SQL Query: Select *
From [Source DE_Like Operator]
Where EmailAddress NOT LIKE '%@gmail.com%'
Target DE:
16. Exclude Duplicate records(Basic):
SQL Query: Select SubscriberKey, FirstName, LastName, EmailAddress, PhoneNumber, City, ProductName, EmailName, Status, BounceCount, CustomerID, LastLoginDate
From [Source DE_Like Operator]
Group By SubscriberKey, FirstName, LastName, EmailAddress, PhoneNumber, City, ProductName, EmailName, Status, BounceCount, CustomerID, LastLoginDate
Having Count (*) = 1
Target DE:
This code has also worked for 16 by creating a separate Target DE Fields:
Select SubscriberKey,
EmailAddress
From [Source DE_Like Operator]
Group By SubscriberKey,
EmailAddress
Having Count (*) = 1
17. Exclude Customer who already purchased: - Need to create a separate DE for purchases
SQL Query: Select *
From [Source DE_Like Operator]
Where CustomerID Not in (Select CustomerID From [SQL_NotLike_OrderDetails])
Target DE:
18. Supression List Inclusion (Very common in SFMC)
3 DE used in this. 1- Source DE, 2. Supression DE with only email address field and records and 3. Target DE
SQL Query: Select *
From [Personalisation DE test]
Where EmailAddress Not in (
Select EmailAddress
From SupressionDE)
Target DE: It sees your existing DE and source DE email address and find the already existing subscribers.
19. Exclude any inactive users (Last 90 days)
SQL Query: Select *
From [Source DE_Like Operator]
Where LastLoginDate > DATEADD(day, -90, GETDATE())
Target DE:
20. Exclude Specific Campaign Audience
SQL Query: Select *
From [Source DE_Like Operator]
Where SubscriberKey Not In (Select SubscriberKey
From [Personalisation DE test])
Personalisation DE Test:
Target DE:
**WHERE SubscriberKey NOT IN (
SELECT SubscriberKey FROM Sent_Data_Extension
)
🔥 Interview Tip (Very Important)
👉 Combine % + exclusion (real-world scenario):
SELECT *
FROM Contacts
WHERE EmailAddress LIKE '%@gmail.com'
AND EmailAddress NOT LIKE '%test%'
💡 Use case:
Target real Gmail users but remove test data → very common in campaigns
(SFMC Specific)
% → Used heavily in Audience Segmentation
NOT / exclusion → Used in Suppression, Journey filtering, Deduplication
Both together → Production-ready queries
Comments
Post a Comment