Solved

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

Posted on 2012-03-14
2
200 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 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

21 Experts available now in Live!

Get 1:1 Help Now