本文给大家介绍有关数据库SQL递归查询在不同数据库中的实现方法,具体内容请看下文。
比如表结构数据如下:
Table:Tree
ID Name ParentId
SQL SERVER 2005查询方法:
//上查 with tmpTree as ( select * from Tree where Id=2 union all select p.* from tmpTree inner join Tree p on p.Id=tmpTree.ParentId ) select * from tmpTree //下查 with tmpTree as ( select * from Tree where Id=2 union all select s.* from tmpTree inner join Tree s on s.ParentId=tmpTree.Id ) select * from tmpTree
查看更多关于有关数据库SQL递归查询在不同数据库中的实现方法的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did32725