In my SQL CE database I have three tables: customer
, list
and customerlist
(a junction table between customer
and list
- as it is a many-to-many relationship).
I am trying to run a query that will display all current lists with also the number of customers who are currently subscribed to that list (counting from customerlist
table).
Here is my current query:
select list.listid, count(customerlist.customerid) as numppl, list.ShortDesc
from list inner join customerlist on list.listid=customerlist.listid
group by list.ShortDesc, list.listid
order by numppl desc
The current structure of this database is:
[Customer] [List] [CustomerList]
CustomerId ListId CustomerListId
Name ShortDesc CustomerId
Other details ListId
This currently returns all the lists who have customers currently assigned to them - but not lists which are empty. Empty lists are hidden.
I would like to modify this query to also display empty lists but I am struggling. My desired output is:
Name numppl
listA 375
listB 45
listC 0
(In the example above, listC is currently not being returned).
Any thoughts on how to also show listC in the query?