我想在子查询中使用别名,但似乎在子查询中无法识别别名
SELECT M.name, (select code from menus where menus.id = M.parent_id) as parent_code
FROM menus as M;
我如何实现这一目标?
我以前使用oracle,这个查询有效。
答案 0 :(得分:1)
试试这个
SELECT m.name
FROM menus as m
WHERE m.parent_id in (
select m1.parent_id
from menus as m1
where m.parent_id = m1.parent_id
);