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

Father / Mother query 2

Status
Not open for further replies.

pwills

Technical User
Sep 14, 2002
54
0
0
GB
My head will explode if I don't crack this soon. I have table like:

Child Father Mother
Bill Bob Jane
Joe Mike Mary

I need the view:

Child Name Relation
Bill Bob Father
Bill Jane Mother
Joe Mike Father
Joe Mary Mother

Can anyone help?
 
Try this:

select child,father as [name],'father' as relation from table
union
select child,mother as [name],'mother' as relation from table
order by child,parent

Hope this helps.
 
I would include ALL on the UNION to prevent SQL Server from sorting and eliminating duplicates. Also, Order By Name rather than Parent or use Parent as the column name in the query as I have done below.

Select Child, father as Parent, 'Father' as Relation
from table

Union All

Select Child, mother, 'Mother' as Relation
From table
Order By child, parent
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top