Answer the question
In order to leave comments, you need to log in
From two pairs of values found by a certain query, how to get the values associated with them from neighboring tables?
Suppose I made some ingenious SELECT (inside it there are still selects and all sorts of WHERE, GROUP, HAVING), which resulted in me, say, two lines in two columns.
All four resulting values are id-shki.
In the end, instead of these id-niks, I need to get their names, which are stored in two more neighboring tables.
I can get the first column, but there are problems with the second one.
So to speak:
SELECT table1.name1, table2.name2
FROM table1, table2
WHERE table1.id IN
(column_1 IN
(мой хитроумный первый SELECT)
)
AND table2.id IN
(column_2 IN
(мой хитроумный первый SELECT)
)
AND table2.id =
(column_2 IN
(мой хитроумный первый SELECT)
)
Answer the question
In order to leave comments, you need to log in
SELECT
t1.name, t2.name
FROM (<your_monstrum_query>) alias
JOIN table1 t1 ON t1.id = alias.id1
JOIN table2 t2 ON t2.id = alias.id2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question