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= invoices.customer_id
GROUP BY customers.id
ORDER BY customers.creation desc
Thanks!
- you need a LEFT JOIN. See http://dev.mysql.com/doc/refman/5.0/en/join.html
- ian
--
+-------------------------------------------------------------------+
| Ian Sales Database Administrator |
| |
| "All your database are belong to us" |
| ebuyer http://www.ebuyer.com |
+-------------------------------------------------------------------+
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]