Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mad marcus
Starting Member
12 Posts |
Posted - 2010-03-29 : 03:01:06
|
| Hi,I have 2 tables like the following - tblFamilyMember-FamilyMemberId PK-FamilyId FK (from the table tblFamily)-PersonsName-etc etctblFamily-FamilyId PK-FamilyName-Father (this is a FamilyMemberId foreign key from the table tblFamilyMember)-Mother (this is a FamilyMemberId foreign key from the table tblFamilyMember)Given the FamilyMemberId what I need to do is produce a record that includes that persons name as well as that persons mothers and fathers names.I think what I need is to include multiple selects in my query but I can't seem to get the syntax right.Any help to put me in the right direction would be much appreciated. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-29 : 03:56:33
|
| [code]SELECT fm.PersonsName AS Person,fm1.PersonsName AS Father,fm2.PersonsName AS MotherFROM tblFamilyMember fmJOIN tblFamily fON f.FamilyId=fm.FamilyIdJOIN tblFamilyMember fm1ON fm1.FamilyMemberId=f.Father JOIN tblFamilyMember fm2ON fm2.FamilyMemberId=f.MotherWHERE f.FamilyMemberId = @YourPassedID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
mad marcus
Starting Member
12 Posts |
Posted - 2010-03-31 : 01:43:56
|
| Thanks visakh16,It appears I was on the wrong track altogether so I appreciate your help. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-31 : 13:30:49
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|