This query is driving me nuts!

I have two tables, affiliates, and advertisers. The advertisers table has an
affiliate_id field, which matches the affiliates tables' primary key. I'm
trying to write a query that will return all affiliate id's, contact names,
and the # of rows in the advertisers table. I'm sure this requires a left
join, but the following query does NOT work:

SELECT af.affiliate_id, af.contact_name, af.contact_email,
count(ad.affiliate_id) AS count
        FROM affiliates AS af LEFT JOIN advertisers AS ad
        ON af.affiliate_id = ad.affiliate_id
        GROUP BY ad.affiliate_id
        ORDER BY count DESC

Note, I want to return all affiliates, even if there are no matching rows in
the advertisers table, which is why I'm assuming a left join is necessary.

TIA,


Daren Cotter


---------------------------------------------------------------------
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