create table node ( id int PRIMARY KEY AUTO_INCREMENT, name varchar(20), next int ); insert into node VALUE (1, '1', 2); insert into node VALUE (2, '2', 3); insert into node VALUE (3, '3', 4); insert into node VALUE (4, '4', 5); insert into node VALUE (5, '5', 6); insert into node VALUE (6, '6', 7); insert into node VALUE (7, '7', 8); insert into node VALUE (8, '8', null); insert into node VALUE (111, '111', 222); insert into node VALUE (222, '222', 333); insert into node VALUE (333, '333', 444); insert into node VALUE (444, '444', 555); insert into node VALUE (555, '555', null); SELECT id, name, next FROM node INNER JOIN ( SELECT 111 AS a # 111换成根节点id UNION SELECT @next_id AS a FROM node, (SELECT @next_id := 111) n # 111换成根节点id WHERE id = @next_id AND @next_id := next # 其他条件 ) ids ON node.id = ids.a; 结果: +-----+------+------+ | id | name | next | +-----+------+------+ | 111 | 111 | 222 | | 222 | 222 | 333 | | 333 | 333 | 444 | | 444 | 444 | 555 | | 555 | 555 | NULL | +-----+------+------+ 递归查询的大概语句是这样,不知道缝缝补补后能否满足你的需求