Hi guys,

I hope this isn't too far off topic, but I'm stuck on an SQL issue and really need some help.

I have a table with these two fields:

UserID  (int)
Referer (int)

UserID is obviously my user's ID number.  Referer refers to the UserID of the person who referred them.  

I need to run an SQL Query that returns to me the total number of records in which a UserID is in the Referer.  

For example, Ted is UserID 1 and John is UserID 2

Ted Refers, Jan, Jerry and Jack

John Refers Mary and Bill

I now have 7 records, all unique UserID's but the referer for Jan, Jerry and Jack is 1 and the referer for Mary and Bill is 2

I want to run an SQL Query that returns the following results:

UserID   NumReferred
1        3
2        2

I know it's GOT to be possible to do it all in SQl.  I know I can do it in CF with no problem by looping over my userid list, but that takes way too long.

Any ideas?

Thanks!

Dave
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to