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 firstname.lastname@example.org email@example.com
Cary Grant firstname.lastname@example.org email@example.com
Mary Smith firstname.lastname@example.org email@example.com
Example of query output:
FNAME LNAME EMAIL REFERRALS
Jane Doe firstname.lastname@example.org 2
John Doe email@example.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!