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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Multiple Selects

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 etc

tblFamily
-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 Mother
FROM tblFamilyMember fm
JOIN tblFamily f
ON f.FamilyId=fm.FamilyId
JOIN tblFamilyMember fm1
ON fm1.FamilyMemberId=f.Father
JOIN tblFamilyMember fm2
ON fm2.FamilyMemberId=f.Mother
WHERE f.FamilyMemberId = @YourPassedID
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

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.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-31 : 13:30:49
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -