Reputation: 11
With this code I will get only customers records with total of orders more than zero, but I need get the customers with zero total of orders also.
How to get all Customers record in Northwind
with and without orders?
thanks for the help.
Upvotes: 1
Views: 1368
Reputation: 1251
Changing INNER JOIN to LEFT JOIN will return customers who do not have orders.
SELECT Customers.CustomerID,
Customers.CompanyName,
COUNT(Orders.OrderID) AS Total
FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
GROUP BY Customers.CustomerID,
Customers.CompanyName
This query returns all customers (91 in the Northwind DB) and the total displays 0 for those who do not have orders.
Is this what you were after?
Upvotes: 1