Count and Joins
Customer
CustomerID Name
4001 John Bob
4002 Joey Markle
4003 Johny Brown
4004 Jessie Black
Orders
OrderID Customer
50001 4001
50002 4002
50003 4001
50004 4003
50005 4001
50006 4003
50007 4001
I tried this join
Select c.Customer, COUNT(o.OrderID) as TotalOrders
from Customer c
inner join Orders o
on c.Customer = o.Customer
Group by c.Customer
But here is the result.
Customer TotalOrders
4001 4
4002 1
4003 2
The customer with no order is not included. How I will include all the
customer even they don't have orders?
Customer TotalOrders
4001 4
4002 1
4003 2
4004 0
No comments:
Post a Comment