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 2000 Forums
 Transact-SQL (2000)
 SQL query(not really server question)

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-08-25 : 10:33:02
Adnan writes "I have two tables as follows:

Table Person

Id Name
------------
1 Tom
2 Mike
3 James
4 Demi
5 Micheal

Table Action

AID Person Action Person
--------------------------------
1 1 xxx 4
2 5 xxx 1
3 2 xxx 3

My question:

How can I get both names from the Action table trough only one query???"

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-08-25 : 10:51:15
Tom xxx Demi
Michael xxx Tom
Mike xxx James


Can I ask how you have 2 columns named Person in 1 table????

basically, you need to join on person1 and join on person2

Select *
from Action A
inner join Person B
on A.person1 = B.person
inner join Person C
on A.person2 = C.person


Corey

Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..."
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-08-25 : 13:16:38
You can join the Person table more than once, just give it a different alias each time.

SELECT A.AID, P1.[Name] AS Person, P2.[Name] AS [Action Person]
FROM Action A
INNER JOIN Person P1 ON A.Person = P1.Id
INNER JOIN Person P2 ON A.Person = P2.Id
Go to Top of Page
   

- Advertisement -