SFMC First-Time vs Repeat Buyers: SQL Audience Guide
Build first-time and repeat buyer audiences in SFMC with one SQL query. Copy-ready code, data extension settings, and the lookback window mistake to avoid.
Marketing teams usually want two very different audiences: people who bought once and need a second order, and people who keep coming back and deserve a loyalty offer. SFMC does not label either group for you. To split first-time vs repeat buyers, you query your order data and store the result in a data extension.
The short answer: group order rows by subscriber, count the orders, label subscribers with exactly one order as first-time buyers, and label everyone else as repeat buyers. Write the result to a data extension keyed on SubscriberKey, and refresh it with a query activity.
This guide covers the query, the data extension settings that keep it reliable, and the edge cases that change who lands in each group. The examples use generic names, so you can map them to your own order data.
Why first-time vs repeat buyers need separate audiences in SFMC
What each group needs from you
First-time buyers usually need help with the second purchase: a welcome series, a product guide, or a reminder that their first order was worth making. Repeat buyers need something different, such as early access, replenishment reminders, or a loyalty offer that rewards the habit they already have.
Sending the same campaign to both groups wastes the attention of first-time buyers and gives repeat buyers nothing new. A single audience with a BuyerType field lets you build both journeys from one source of truth.
The split also changes how you read results. Conversion rates for the two groups tell different stories, so report them separately. Blending them can hide the fact that most revenue comes from a small repeat group, or that first-time buyers leave before their second order.
If you want to describe the split in plain English and get the SQL back, generate SFMC SQL from plain English handles that step. The rest of this guide shows the query so you can check every line before you trust it.
The SQL query for first-time vs repeat buyers
The query below assumes an order history data extension named Order_History with one row per order. It has the fields SubscriberKey, OrderID, OrderDate and OrderStatus. Replace those names with your own.
SELECT
o.SubscriberKey,
COUNT(o.OrderID) AS OrderCount,
MIN(o.OrderDate) AS FirstOrderDate,
MAX(o.OrderDate) AS LastOrderDate,
CASE
WHEN COUNT(o.OrderID) = 1 THEN 'First-time'
ELSE 'Repeat'
END AS BuyerType
FROM Order_History o
WHERE o.OrderDate >= DATEADD(month, -24, GETDATE())
AND o.OrderStatus = 'Completed'
GROUP BY o.SubscriberKey
Here is what each part does:
- SELECT returns one row per subscriber, because GROUP BY on SubscriberKey collapses all of their orders.
- COUNT(o.OrderID) counts the orders inside the window. This number decides the buyer type.
- MIN and MAX on OrderDate give the first and most recent order dates inside the window.
- The CASE expression labels exactly one order as First-time and anything above one as Repeat.
- DATEADD and GETDATE limit the lookback to 24 months. Change the -24 to match your purchase cycle.
- The OrderStatus filter stops cancelled or failed orders from counting as purchases.
You might wonder why this uses GROUP BY instead of ROW_NUMBER(). ROW_NUMBER() is the right tool when you need one specific order per subscriber, such as their latest product or their most recent coupon. For a count-based label, aggregate functions are shorter, easier to read, and easier for the next person on your team to check.
Data extension and query activity settings
Create the target data extension as Buyer_Segments with SubscriberKey as a text primary key. The primary key is safe here because GROUP BY on SubscriberKey returns each subscriber once. Set the query activity to Overwrite. Overwrite rebuilds the table on every run, so a subscriber who stops buying drops out of the audience automatically.
The query activity offers three data actions: Append, Update and Overwrite. Overwrite fits a segment you rebuild each time, while Update and Append are for different load patterns. The Overwrite, Update and Append guide explains the differences in more detail.
Use Validate Syntax before you save, and remember that queries time out after 30 minutes. For the basics of query activities, Trailhead's query data with SQL module is a good starting point.
Build the audience in five steps
- Confirm which data extension holds your order history and that it has one row per order, not one row per product line.
- Run the query with a short window first, and check that the row count matches the number of customers you already know.
- Create Buyer_Segments with SubscriberKey as a text primary key, and make sure the field cannot be empty.
- Add the query activity to an automation set to Overwrite, and schedule it to finish before your next send or journey entry.
- Check five subscribers by hand against their order history before any campaign uses the audience.
Step five is the one teams skip, and it catches most errors. A wrong status filter or a join that duplicates rows shows up quickly when you compare a few real customers to the output.
Edge cases that change who counts as a first-time buyer
The lookback window decides what first-time means
The query only sees orders inside the window. A subscriber who bought three years ago and once in the last 24 months shows up as First-time, even though they are a returning customer. If that distinction matters, run a second pass over the full history with MIN on OrderDate and a count with no date filter, then combine the two results before you write the audience.
Pick the window on purpose. Twelve or 24 months suits many retail and subscription programs. Name the audience so the window is visible, for example Buyers_First_Time_24M, so nobody reads it as lifetime history by mistake.
Refunds, cancellations and test orders
Order exports often include cancelled, refunded or test orders. Each one inflates the order count and can move a first-time buyer into the Repeat group. Filter on the status values your order system uses, and confirm the filter against a few known orders.
Also use SubscriberKey, not email address, as the grouping key. Email addresses change and can be updated partway through a window. If one customer appears under two addresses, the count splits and the label is wrong. SubscriberKey is the identifier your sends use, so it is the safer choice. Teams that already score customers can combine this split with RFM segmentation in SFMC for a finer view.
FAQ
How do I count repeat purchases in SFMC SQL?
Use COUNT on the order ID, grouped by SubscriberKey. Any subscriber with a count of two or more has made a repeat purchase inside the window you set. Keep the order status filter in place so cancelled orders do not count.
Should first-time buyers use a 12-month or a lifetime window?
A lifetime window gives the most accurate first-time label, but it is heavier to run on large order tables. Many teams use 12 or 24 months and put the window in the audience name, so the label stays honest.
Why does my target data extension show duplicate subscribers?
Duplicates usually come from a query that returns one row per order instead of one row per subscriber. The GROUP BY on SubscriberKey prevents that in the example. If you add joins to other tables, check that each join does not multiply rows before you set the primary key. The guide to joining two data extensions covers the INNER and LEFT JOIN differences.
Can the audience refresh automatically?
Yes. Place the query activity in an Automation Studio automation and schedule it to run before your sends. Check the first few runs, because a schedule that starts before the order data has loaded will produce a smaller audience than expected.
Build this audience with QAiry
Writing this query by hand takes time, and a small mistake in a window or a status filter changes who receives which message. QAiry turns a plain-language request, such as first-time buyers from the last 24 months, into production-ready SFMC SQL and the matching data extension, so you can review the query before it runs.
To see the workflow on your own data model, start the free install or watch the product demos.

