I don’t have much experience with advanced queries, but this is what I am trying to accomplish:
a table in my database has a field for “referrer” which records the name of the person who referred that user to the site. I need to write a query that will, for each user in the table, count how many referrals they have, and output their information with the referral count.
example of table:
FNAME LNAME EMAIL REFERRER
John Doe jdoe@email.com janedoe@yahoo.com
Cary Grant cgrant@email.com janedoe@yahoo.com
Mary Smith msmith@email.com jdoe@email.com
Example of query output:
FNAME LNAME EMAIL REFERRALS
Jane Doe janedoe@yahoo.com 2
John Doe jdoe@email.com 1
I can write a query to count how many referrals a user has if I pass the user’s info in the query (WHERE referrer = ‘example’), but I don’t know how to count AND output data for all of the users in the database in one query. I am thinking this is a subquery situation, but I don’t know where to begin. Any help is greatly appreciated!