📢📢 Join the Party - Our Discord Server is Now Open and Completely FREE!

background shape
background shape

NOT EXISTS vs NOT IN in Salesforce Marketing Cloud SQL

When writing SQL queries in Salesforce Marketing Cloud Engagement (MCE) formerly Salesforce Marketing Cloud (SFMC), speed isn’t just a nice-to-have — it’s a necessity. Query Activities that exceed 30 minutes will timeout, making efficient SQL is often a must.

One of the most common SQL tasks is excluding records: “Give me people who are in Table A but not in Table B.”

Simple right?

Well — not all SQL is created equal.

In MCE (SFMC), every Query Activity must complete within 30 minutes. If a query runs longer, it fails — no data, no results, no mercy.
This makes query speed and efficiency critical when building exclusion logic.

Today we’ll compare three popular approaches:

  • LEFT JOIN + IS NULL
  • NOT IN (SELECT …)
  • NOT EXISTS (SELECT …)

and find out which one is the fastest and safest for SFMC.

LEFT JOIN + IS NULL

SELECT a.EmailAddress
FROM ent._Subscribers a
LEFT JOIN Sent b ON a.SubscriberKey = b.SubscriberKey
WHERE b.SubscriberKey IS NULL

This joins both tables and filters for rows where the match in _Sent view is missing. That means we get subscribers that we have not sent any email in last 6 months.

NOT IN (Subquery)

SELECT a.EmailAddress
FROM Subscribers a
WHERE a.SubscriberKey NOT IN (
    SELECT SubscriberKey
    FROM Sent
)

NOT EXISTS (Subquery)

SELECT a.EmailAddress
FROM Subscribers a
WHERE NOT EXISTS (
    SELECT 1 
    FROM Sent b 
    WHERE a.SubscriberKey = b.SubscriberKey
)

How They Perform in MSSQL

MethodPerformance (Speed)Risk of ErrorsNotes
LEFT JOIN + IS NULL🟡 Medium✅ SafeCan slow down with large joins.
NOT IN🔴 Slow on large data❌ Risky with NULLsIf the subquery returns NULLs, results break.
NOT EXISTS🟢 Fastest✅ SafeOptimizes best at scale.
  • NOT EXISTS is fastest because MSSQL short-circuits once it finds a match — it doesn’t scan the whole subquery.
  • LEFT JOIN builds a full result set before filtering out NULLs. More overhead = slower on large datasets.
  • NOT IN forces SQL Server to materialize a full list first — and NULLs can cause all rows to be excluded, creating bugs and extra runtime.

Real-World Estimates

Method~Time on 1M Records
LEFT JOIN + IS NULL~15–25 seconds
NOT IN (subquery)~25–40 seconds (if no NULLs)
NOT EXISTS (subquery)~8–15 seconds

đź’¬ Important: In Salesforce Marketing Cloud, since Data Extensions are often shared across customers and storage isn’t indexed like a normal database, expect those times to vary — but NOT EXISTS will still be the fastest relatively.

Picking the right SQL structure can mean the difference between a query that finishes in 10 minutes… or one that never finishes at all.

Oh hey there đź‘‹
I’ve got something special for you—free scripts every month!

Sign up now to receive monthly Salesforce Marketing Cloud script examples straight to your inbox.

We don’t spam! Read our privacy policy for more info.

Share With Others

MarTech consultant

Marcel Szimonisz

Marcel Szimonisz

I specialize in solving problems, automating processes, and driving innovation through major marketing automation platforms.