HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Selecting 2 column in an Inner join

Submitted by: @import:stackexchange-dba··
0
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.

SELECT Title as SourceTitle 
FROM Result Map AS RM 
INNER JOIN Table_Result TR ON RM.SourceId = TR.Id


The 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:

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         DEF

Code 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         DEF

Context

StackExchange Database Administrators Q#248503, answer score: 9

Revisions (0)

No revisions yet.