select id,parentid from a start with parentid ='00000' 
 connect by prior  id = parentid;Note:the position of id and parentid

解决方案 »

  1.   

    select id,parentid from a start with id='00000' connect by prior id=parentid;
      

  2.   

    thanx: xiapb(nirvana) & chooser(chooser)sql语句能执行,但好象不能选全部的记录,能具体解释一下
    start with...connect by prior....的意义吗?
      

  3.   

    connect by 是结构化查询中用到的,其基本语法是:
    select ... from tablename start by cond1
    connect by cond2
    where cond3;
    简单说来是将一个树状结构存储在一张表里,比如一个表中存在两个字段:
    id,parentid那么通过表示每一条记录的parent是谁,就可以形成一个树状结构。
    用上述语法的查询可以取得这棵树的所有记录。
    其中COND1是根结点的限定语句,当然可以放宽限定条件,以取得多个根结点,实际就是多棵树。
    COND2是连接条件,其中用PRIOR表示上一条记录,比如 CONNECT BY PRIOR ID=PRAENTID就是说上一条记录的ID是本条记录的PRAENTID,即本记录的父亲是上一条记录。
    COND3是过滤条件,用于对返回的所有记录进行过滤。
    具体细节还是需要看看书,这个东东很有用的。
      

  4.   

    有一张表 t
    字段:
    parent
    child
    两个字段的关系是父子关系写一个sql语句,查询出指定父下面的所有的子比如a b
    a c 
    a e
    b b1
    b b2
    c c1
    e e1
    e e3
    d d1指定parent=a,选出
    a b
    a c 
    a e
    b b1
    b b2
    c c1
    e e1
    e e3SQL语句:
    select parent,child from test start with parent='a'
    connect by prior child=parent