background shape
background shape

NOT EXISTS vs NOT IN vs LEFT JOIN in SFMC Queries

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 hi there 👋
I have a FREE e-book for you.

Sign up now to get an in-depth analysis of Adobe and Salesforce Marketing Clouds!

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.

Buy me a coffee
Subscribe

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome content in your inbox, every month.

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

If the form isn't cooperating, don't worry. Just drop us an email at info(at)martechnotes(dot)com with 'Subscribe' in the subject line, and we'll be happy to add you to our list. As a token of our appreciation, we'll also send you a free e-book. Your subscription means a lot to us, and we want to ensure you don't miss out on our valuable content.