homepage Welcome to WebmasterWorld Guest from 54.161.214.221
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Select for when Two People Attended Event
Frank_Rizzo




msg:4484972
 10:48 am on Aug 15, 2012 (gmt 0)

I need to find records for when two specific people attended an event. I can do this via looping within php but there must be a solution via a select?

EVENT_NO, NAME
--------------
1001, A David
1001, B Elwood
1001, Z Griswold
1002, A David
1002, C Johnson
1002, D Smith
1003, A David
1003, C Johnson
1003, Z Griswold

What I want to extract are the records where A David and Z Griswold both attended the same event:

1001, A David
1001, Z Griswold
1003, A David
1003, Z Griswold

 

Dijkgraaf




msg:4485241
 11:35 pm on Aug 15, 2012 (gmt 0)

Something like the following ( you will have to substitute the correct table name).

SELECT EVENT_NO, NAME
FROM EVENT_TBL
WHERE EXISTS
(
SELECT 1 FROM EVENT_TBL AS EVENT_TBL2
WHERE EVENT_TBL.NO = EVENT_TBL2.NO
AND EVENT_TBL.NAME <> EVENT_TBL2.NAME
)
ORDER BY EVENT_NO, NAME

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved