当我在where子句中使用子查询别名时,我得到了未知列错误:
SELECT name,
(SELECT id FROM category c2 WHERE c2.parent_id=23) children
FROM category c1 WHERE c1.id IN children;
有人能说出为什么这段代码不起作用吗?
答案 0 :(得分:1)
反过来说:
SELECT name,
FROM category c1
WHERE c1.id IN (SELECT id FROM category c2 WHERE c2.parent_id=23);
答案 1 :(得分:0)
我认为你可以在没有子选择的情况下进行查询
select a.name, b.id as children
from category as a
inner join category b on ( a.c1.id = b.id and b.parent_id = 23 );