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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select question

Status
Not open for further replies.

tennisblues

Programmer
Oct 11, 2002
1
US
hi,
i am new to sql statemsnts, so please forgive me......

i have 2 tables:
Member
memberid int(6)
firstname varchar(20)
lastname varchar(20)

Grouping
groupid int(6)
memberid int(6)
visitor varchar(40)

the idea is that a grouping can have 1-n members or if someone isnt a member, then i just put the full name in the visitor column and a 0 in the memberid.....

so now my question is how do i select everyone in a grouping and get the full name out....

i tried
SELECT Member.FirstName, Member.LastName, Grouping.SubName FROM Member, Grouping WHERE 4 = Grouping.GroupID and Grouping.MemberID = Member.MemberID

but this is not getting the visitor names. can someone please point me in the right direction?

thanks so much in advance!
 
possibly this:
SELECT M.FirstName, M.LastName FROM Member M, Grouping G WHERE M.MemberID = G.MemberID and G.GroupID = '4'; ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
It sounds like you want to get a name regardless of whether the person is a member or just a visitor. So, you need to get all "Grouping" records and any matching "Member" records. This requires an OUTER JOIN. The LEFT OUTER JOIN ("OUTER" is optional) gets all records from the Grouping table, even if the record doesn't have a matching Member record.

Here's the query:

SELECT m.firstname, m.lastname, g.visitor
FROM Grouping AS g LEFT JOIN Member AS m ON g.memberid = m.memberid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top