1068 Customer Orders

table of content

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

  1. Use a LEFT JOIN:
    • We join Customers and Orders tables using customerID:
    FROM Customers AS c
    LEFT JOIN Orders AS o
    ON c.customerID = o.customerID
    
    • Since Customers contains all customer records, the LEFT JOIN ensures that customers without a matching order will have NULL values in the Orders table.
  2. 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.img