sql根据父id查询子项数据

来源:互联网 发布:android 手机淘宝源码 编辑:程序博客网 时间:2024/05/20 02:54

查询所属id及其子项数据

with CategoryIds as
(
  select id from ProductCategory where ParentId=102 or id=102
  union all
  select a.id from ProductCategory a join CategoryIds b on a.ParentId=b.Id where a.ParentId is not null  
)
select * from ProductCategory where  id in(select id from CategoryIds)


0 0