First off, I would like to thank everyone on this lists who helps people
like myself!

I'm having trouble with the following query:
SELECT username, first_name, email, DATE_FORMAT(signup_date, '%b %e,
%Y') AS signup_date FROM members WHERE referer = (id)

It selects a list of all members from the database referred by a certain
member. However, the query needs to be modified to also select the
number of people that person has referred. I planned to just send
another query looping through the results, but if a member has referred
100 people, that's 100 queries, and probably not the best idea? So to do
this query, do I need to left join the table to itself? Maybe something
like:

SELECT m1.username, m1.first_name, m1.email, DATE_FORMAT(m1.signup_date,
'%b %e, %Y') AS signup_date, COUNT(m2.id) AS count FROM members AS m1
LEFT JOIN members AS m2 ON m1.referer = m2.id WHERE m1.referer = 4 GROUP
BY m1.referer

Is that even close? heh


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