On 11 Jul 2002, at 17:41, Witness wrote:

> SELECT  DISTINCT affiliates.id, DISTINCT
> sales.client_id,SUM(sales.client_id)
>  FROM affiliates,clients,sales
>  WHERE affiliates.id = clients.affiliate_id AND sales.client_id =
> clients.id;

I don't think that's what Daren wanted.  For one thing, I doubt it's 
meaningful to sum client IDs.  Maybe something more like this:

   SELECT a.id as affiliate_id, COUNT(s.id) as sales_count
   FROM affiliates a LEFT JOIN clients c ON a.id = c.affiliate_id
        LEFT JOIN sales s ON c.id = s.client_id
   GROUP BY a.id;

[Filter fodder: SQL]

-- 
Keith C. Ivey <[EMAIL PROTECTED]>
Tobacco Documents Online
http://tobaccodocuments.org

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to