Find Your Inactive Customers: SQL Query for No Orders in 90 Days
SELECT c.customer_id, c.first_name, c.last_name, c.email
FROM Customers c
WHERE NOT EXISTS (
SELECT 1
FROM Orders o
WHERE o.customer_id = c.customer_id
AND o.order_date >= CURRENT_DATE - INTERVAL '90 days'
);Identifying inactive customers is a critical step for businesses looking to boost engagement and reduce churn. This SQL query helps you precisely pinpoint customers who have not made a purchase within a specified timeframe, in this case, the last 90 days.
This query works by first selecting all customer information from your Customers table. It then uses a WHERE NOT EXISTS clause combined with a subquery on the Orders table. The subquery checks for any orders placed by that customer within the last 90 days (relative to the current date). If no such order exists for a customer, they are included in the final result, effectively identifying your inactive customer base.
You can easily adapt this query for different date ranges (e.g., INTERVAL '6 months'), specific customer segments, or to include additional customer details. Use this powerful insight to launch targeted re-engagement campaigns, special offers, or feedback requests to bring these customers back into your active base. Need to adjust it for your specific database or add more complexity? Our SQL Query Generator can help.