在某些条件下使用单个查询查找mysql表中的所有父项

时间:2013-08-07 10:03:17

标签: mysql hierarchical-data

下一步SQL正在运行:

SELECT T2.id, T2.name 
FROM (
    SELECT
        @r AS _id,
        (SELECT @r := IDParent FROM objects WHERE id = _id) AS parent_id
    FROM
        (SELECT @r := 10) vars,
        objects m
    WHERE @r <> 0) T1
JOIN objects T2
ON T1._id = T2.ID

但我只能通过查询找到ID:

SELECT ID FROM objects WHERE LOWER(name) LIKE LOWER('%prod%')

告诉我如何组合这些查询

0 个答案:

没有答案