Solved

Join a Table where the two columns need to be linked to single column in joined table

Posted on 2012-03-14
2
202 Views
Last Modified: 2012-06-21
Hi,

I have the situation where I need to join a table where two columns within this table need to be linked to
the same column in the other (join) table. I use the following script below but it seems this does not
retrive the result sets i wanted. Can someone please help?

SELECT  
  t1.[PaymentID],
  t1.[PaymentFrom],  t2.[Client Name],
  t1.[PaymentTo],  t2.[Client Name]
FROM [Payments] t1 INNER JOIN [ClientDetails] t2
ON t1.[PaymentFrom] = t2.[ClienId] AND t1.[PaymentTo] = t2.[ClientId]


Table [Payments]
  [OrderID]
  [PaymentID]
  [PaymentFrom]
  [PaymentTo]

Table [ClientDetails]
  [ClientID]
  [Client Name]
  [Contact]
0
Comment
  • 2
2 Comments
 
LVL 12

Accepted Solution

by:
Paul_Harris_Fusion earned 500 total points
ID: 37723099
I am guessing that the payment from client might be different to the payment to client.  
In which case, you need to include the client table twice

SELECT  
  P.[PaymentID],
  P.[PaymentFrom],  F.[Client Name] as FROM_NAME
  P.[PaymentTo],  T.[Client Name] as TO_NAME
FROM Payments P
INNER JOIN ClientDetails F ON P.PaymentFrom = F.ClientId
INNER JOIN ClientDetails T ON P.PaymentTo = T.ClientId
0
 
LVL 12

Expert Comment

by:Paul_Harris_Fusion
ID: 37747461
Hello - have you abandoned this question?    If so could you close it off in some way and let me know if my solution was successful.......
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now