I have a table called concept-relation that contains 3 columns
(relationID, firstConceptID, secondConceptID)
I have a table called concept contains 2 columns
(ID, name)
I want to get the name for the firstConceptID and secondConceptID when the relationID = 22.
This is the query that I came up with.
select * from (
select name as source from concept where concept.ID in (
select firstConceptID from `concept-relation` where relationID = 22
)
) as e,
(
select name as des from concept where concept.ID in (
select secondConceptID from `concept-relation` where relationID = 22
)
)as e
It works well, but I want to know what is the best practice for carrying out such queries?
Need a self-join to make it cleaner usually considered more of a best practice as it avoids the sub selects / “IN”s