一个项目表 project
有 id ,fatherid ,name 就这个三个列
select * from project where id in (1,2,3) 这个一句是选出 项目 为 1 2 3 的项目
项目 1 2 3 分别是 4 5 6 的子项目.现在我要在一条 记录 里面出现 子项目id 子项目名称 子项目的父项目id 子项目的父项目名称
有 id ,fatherid ,name 就这个三个列
select * from project where id in (1,2,3) 这个一句是选出 项目 为 1 2 3 的项目
项目 1 2 3 分别是 4 5 6 的子项目.现在我要在一条 记录 里面出现 子项目id 子项目名称 子项目的父项目id 子项目的父项目名称
这是一个内连接应用,试试看,如果可行的话别忘了稍微给点分吧,我还0分呢!
select a.*, b.name from project a, project b where a.fatherid=b.id and a.id in (1,2,3)
select a.id,a.name,b.id,b.name
from project a, project b
where a.id = b.fatherid