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 |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-08-25 : 10:33:02
|
Adnan writes "I have two tables as follows:Table PersonId Name------------1 Tom2 Mike3 James4 Demi5 MichealTable ActionAID Person Action Person--------------------------------1 1 xxx 42 5 xxx 13 2 xxx 3My 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 DemiMichael xxx TomMike xxx JamesCan I ask how you have 2 columns named Person in 1 table????basically, you need to join on person1 and join on person2Select * from Action Ainner join Person Bon A.person1 = B.personinner join Person Con A.person2 = C.personCorey 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 ..." |
 |
|
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 AINNER JOIN Person P1 ON A.Person = P1.IdINNER JOIN Person P2 ON A.Person = P2.Id |
 |
|
|
|
|