patternsqlMinor
Selecting 2 column in an Inner join
Viewed 0 times
joininnerselectingcolumn
Problem
Below are my two tables :
I am trying to write a query that joins these 2 tables AND returns the Source_Title and Destination_Title for the given Source ID of Result Map table.
I have tried written the query, but I can only solve one part of the puzzle not the whole thing.
The above query gives me the title for the source, but not the Destination title.
I am trying to write a query that joins these 2 tables AND returns the Source_Title and Destination_Title for the given Source ID of Result Map table.
I have tried written the query, but I can only solve one part of the puzzle not the whole thing.
SELECT Title as SourceTitle
FROM Result Map AS RM
INNER JOIN Table_Result TR ON RM.SourceId = TR.IdThe above query gives me the title for the source, but not the Destination title.
Solution
Benjamin.
If I understood you correctly, you want something like this:
The query will return
If I understood you correctly, you want something like this:
SELECT TR1.Title AS SourceTitle,
TR2.Title AS DestinationTitle
FROM [Result Map] AS RM
INNER JOIN Table_Result TR1 ON RM.Source_Id=TR1.Id
INNER JOIN Table_Result TR2 ON tr2.Id=RM.destination_id;The query will return
SourceTitle DestinationTitle
ABC DEFCode Snippets
SELECT TR1.Title AS SourceTitle,
TR2.Title AS DestinationTitle
FROM [Result Map] AS RM
INNER JOIN Table_Result TR1 ON RM.Source_Id=TR1.Id
INNER JOIN Table_Result TR2 ON tr2.Id=RM.destination_id;SourceTitle DestinationTitle
ABC DEFContext
StackExchange Database Administrators Q#248503, answer score: 9
Revisions (0)
No revisions yet.