Answer the question
In order to leave comments, you need to log in
How to apply INNER JOIN to query result?
Good day: there is a query that displays a table with all child submenus of the main menu.
Objective: to apply an INNER JOIN to the given result, but I don't know how to do it exactly.
Request:
SET @var = 4;
SELECT *
FROM menu
WHERE FIND_IN_SET(ID,(SELECT GROUP_CONCAT(lv SEPARATOR ',') FROM (
SELECT @pv:=(SELECT GROUP_CONCAT(ID SEPARATOR ',')
FROM menu WHERE submenu IN (@pv)) AS lv FROM menu
JOIN (SELECT @pv:[email protected]var)tmp
WHERE submenu IN (@pv)) a))
UNION ALL
SELECT *
FROM menu
WHERE ID = @var
ORDER BY ID;
Answer the question
In order to leave comments, you need to log in
Something to connect with...
SET @var = 4;
Select * from
(
-------------Ваш сложный подзапрос --------------------
SELECT *
FROM menu
WHERE FIND_IN_SET(ID,(SELECT GROUP_CONCAT(lv SEPARATOR ',') FROM (
SELECT @pv:=(SELECT GROUP_CONCAT(ID SEPARATOR ',')
FROM menu WHERE submenu IN (@pv)) AS lv FROM menu
JOIN (SELECT @pv:[email protected]var)tmp
WHERE submenu IN (@pv)) a))
UNION ALL
SELECT *
FROM menu
WHERE ID = @var
ORDER BY ID
-------конец сложного подзапроса--------------
) complicated_menu
inner join ваша_таблица vt on complicated_menu.id = vt.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question