L
L
lordprotein2020-02-26 21:23:32
MySQL
lordprotein, 2020-02-26 21:23:32

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;


Result:
YVHm7pBgwjE.jpg

PS The code was borrowed from

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alexalexes, 2020-02-26
@lordprotein

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

D
d-stream, 2020-02-26
@d-stream

select
*
from ( select .... ) as abc
inner join (select ...) as js on ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question