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

Using 2 tables and getting values out of one

Status
Not open for further replies.

GKoehn

Programmer
Oct 11, 2001
2
US
I have a table which holds contacts. these contacts are linked to each other useing a link table. for example:
-----------------------------------
Contacts Table:
recordid name
1 joe somebody
2 jane kane
-----------------------------------
link table:
recordid parentid linkedid
1 1 2
-----------------------------------

for every row in the link table I'd like to return a column
holding the parent name and a column holding the linked name.

Any ideas how I could do this with SQL.
 

Here is one possiblity. It uses the Link table to link to the Contacts table twice.

Select
b.name As ParentName,
c.name As LinkedName
From Links As a
Inner Join Contacts As b
On a.ParentId=b.RecordID
Inner Join Contacts As c
On a.LinkedId=c.RecordID Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top