I have a mapping table that can hold IDs from the same table.
For example I have :
Variables ( Table )
Values ( Table)
Variables_Values ( Mapping table )
The mapping table has the following fields :
VariableID
To_VariableID
To_ValueID
So it is possible for a row to have two variable IDs, or a variable ID and a value ID.
It is always a pair, so there cannot be two variable IDs and a value ID at the same time.
Now, in the Variables and Values tables, there is a Name field, so variables and values also have names.
I want to create a query that will display the names based on the IDs in the mapping table, but I am not sure how.
Right now I have a query that returns results that look like this :
VariableName To_VariableID To_ValueID
I would like to display VariableName_2, ValueName instead of To_VariableID To_ValueID.
Is there a technique for this?
Could it be a combination of the following queries?
SELECT map.ID, map.TransitionID, variable.Name
FROM Variables AS variable INNER JOIN Mapping AS map
ON variable.VariableID = map.VariableID
SELECT variable.VariableID, variable.Name
FROM Variable AS variable
WHERE variable.VariableID IN ( SELECT map.To_VariableID FROM Mapping AS map)
SELECT value.Name
FROM Values AS value
WHERE value.ValueID IN ( SELECT map.To_ValueID FROM Mapping AS map)
Thank you.
It was as simple as this :