Brian Dunning [EMAIL PROTECTED] wrote on 02/11/2005 16:22:29:
I'm trying to find a list of customers including a count of all their
invoices, but it's not including customers who have no invoices - and
it should. What's broken?
SELECT customers.company, count(invoices.id) as invcount
Brian Dunning wrote:
I'm trying to find a list of customers including a count of all their
invoices, but it's not including customers who have no invoices - and
it should. What's broken?
SELECT customers.company, count(invoices.id) as invcount
FROM customers, invoices
WHERE customers.id=
Hi Mike,
You'll need to use a LEFT JOIN instead of an INNER JOIN.
LEFT JOIN returns mismatches between tables.
Try something like:
SELECT customers.company, count(invoices.id) as invcount
FROM customers
LEFT JOIN invoices ON customers.id= invoices.customer_id
GROUP BY customers.id
ORDER BY
[EMAIL PROTECTED] wrote:
Brian Dunning [EMAIL PROTECTED] wrote on 02/11/2005 16:22:29:
I'm trying to find a list of customers including a count of all their
invoices, but it's not including customers who have no invoices - and
it should. What's broken?
SELECT customers.company,
Thanks very much to all of you!
Obviously I need to learn more about joins. Appreciate the kick in
the pants.
:)
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]