The second, 'friends', lists members who are friends of an individual member as follows
mrn = the member's record number
frn = the record number of a member who is a friend of the member in mrn
I want to look at all members who attended an event on, say, 2012-08-24, and determine if any of them were friends of member 1515.
If no attendees were friends, then the query should return 0 rows.
If at least one attendee is a friend of 1515, then the query should return more than 0 rows.
For this query, I don't actually need the data... I just need a yes/no answer on whether friends of 1515 attended, so I figured I'd get that from the number of rows returned. In the case above, there would be 1 row.
I'm not even coming close to figuring out how to construct that query so any help will be greatly appreciated.
Cheers
CTB
Oh Lord, please help me be the person my dog thinks I am.
SELECT COUNT(*) AS num_friends_attending
FROM attendees
INNER JOIN friends ON attendees.mrn = friends.frn
WHERE friends.mrn = 1515 AND attendees.date='2012-08-24'
Off hand, I don't know if that would be more or less efficient than using a sub-query, e.g.:
Code:
SELECT COUNT(*) AS num_friends_attending
FROM attendees
WHERE date='2012-08-24' AND mrn IN(
SELECT frn FROM friends WHERE mrn=1515
)
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks