I'm trying to determine some marketing statistics using 3 tables (sales_opp_source, sales_opp, contract). I want to show ALL of the sales_opp_source records and show how many accepted contracts there have been for each of those sales_opp_source's (including the ones that would be 0).
sales_opp_source ------------------------- id name
sales_opp -------------- id sales_opp_source_id
contract ----------- id sales_opp_id status
I basically need to do a LEFT JOIN from sales_opp_source to the results of an INNER JOIN between sales_opp and contract, but in the following code, I only get back the sales_opp_source's that actually have a contract. I want to get back all of the sales_opp_source's whether they have a sales_opp/contract or not.
SELECT sales_opp_source.name, count(contract.id) as contract_count FROM sales_opp_source LEFT JOIN sales_opp ON sales_opp_source.id = sales_opp. sales_opp_source_id INNER JOIN contract ON sales_opp.id = contract. sales_opp_id GROUP BY name;
Thanks.
Chris Fowler
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]