赢友网络

递归查询子类sql

--通过父节点查询子节点
WITH 
TREE AS( 
    SELECT * FROM Role 
    WHERE RoleID = 4  -- 要查询的父 id 
    UNION ALL 
    SELECT Role.* FROM Role, TREE 
    WHERE Role.ParentRoleID = TREE.RoleID
) 
SELECT * FROM TREE

  

posted @ 2015-01-27 12:01  新生帝  阅读(189)  评论(0编辑  收藏  举报
赢友网络