SELECT
categories.id, categories.name
AS
parentName
FROM
categories
INNER JOIN
categories
ON
categories.parent = categories.id
ORDER BY
id
DESC
我想在同一个表(类别)中连接两列。
答案 0 :(得分:1)
因为您要加入同一个表,因为需要使用表别名以避免混淆,如下所示
FROM
categories
INNER JOIN
categories
将其更改为以下(此处为c1,c2为表别名)
FROM
categories c1
INNER JOIN
categories c2
ON
c1.parent = c2.id
并相应地调整SELECT子句