Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi Table Select Statement 1

Status
Not open for further replies.

sila

Technical User
Aug 8, 2003
76
0
0
GB
Hi
I hope someone can halp me, I have the following tables:
Code:
Members
member_id

CommitteeMembers
committee_member_id
committee_id
member_id

Committees
committee_id
committee_name

AdvisoryGroupMembers
advisory_member_id
advisory_group_id
member_id

AdvisoryGroups
advisory_group_id
advisory_group_name

I need to be able to select as one list the advisory groups and committees that a member id belongs to. Any help greatly appreciated.

Thanks
 
What have you tried? You will need to do two outer joins and two inner joins as far as i can tell.
 
If you just want a single list of advisory groups and committees for a particular member id try this:

Code:
SELECT c.committee_name
FROM committees c JOIN committeemembers cm ON c.committee_id = cm.committee_id
WHERE cm.member_id = 123
UNION ALL
SELECT ag.advisory_group_name
FROM advisorygroups ag JOIN advisorygroupmembers agm ON ag.advisory_group_id = agm.advisory_group_id
WHERE agm.member_id = 123

--James
 
James

One more question on this query I've just realised! Both the tables CommitteeMembers and AdvisoryGroupMembers also have a field called 'position' which links to a table called Position where the position_name can be selected for the committee/advisory group how do I go about adding this in also?

Thanks
 
Code:
SELECT c.committee_name, p.position_name
FROM committees c
  JOIN committeemembers cm ON c.committee_id = cm.committee_id
  JOIN position p ON cm.position_id = p.position_id
WHERE cm.member_id = 123
UNION ...

I'll let you figure out the rest... ;-)

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top