Hi,
I'm a little bit stumped trying to put together a query that will list a customer Id, and the number of times their Id appears in the History table.
I'm using two tables (simplified);
Customers
id
Name
History
id
CustomerId
I tried the following query;
SELECT a.id,count(a.id) CONTACTS
FROM Customers a, History b
WHERE (a.id = b.CustomerId)
GROUP BY b.CustomerId
ORDER BY CONTACTS;
This works fine, however it doesn't display customers with no entries in the History table -- I need customers with no contacts to show up with '0'.
Any thoughts?
thanks.
I'm a little bit stumped trying to put together a query that will list a customer Id, and the number of times their Id appears in the History table.
I'm using two tables (simplified);
Customers
id
Name
History
id
CustomerId
I tried the following query;
SELECT a.id,count(a.id) CONTACTS
FROM Customers a, History b
WHERE (a.id = b.CustomerId)
GROUP BY b.CustomerId
ORDER BY CONTACTS;
This works fine, however it doesn't display customers with no entries in the History table -- I need customers with no contacts to show up with '0'.
Any thoughts?
thanks.