1068 Customer Orders
To identify customers who never placed an order, we need to find records where a customer exists in the Customers table but does not have a corresponding entry in the Orders table.
Approach
- Use a
LEFT JOIN:- We join
CustomersandOrderstables usingcustomerID:
FROM Customers AS c LEFT JOIN Orders AS o ON c.customerID = o.customerID- Since
Customerscontains all customer records, theLEFT JOINensures that customers without a matching order will have NULL values in theOrderstable.
- We join
- Filter out customers with orders:
- We select customers where there is no corresponding order:
WHERE o.customerID IS NULL
Conclusion
By using this query, we correctly extract all customers who have never placed an order, ensuring that we do not count customers with even a single order.