create table tb3 ( id varchar2(3), name varchar2(10), p_id varchar2(3), constraint pk_tb3id primary key (id));insert into tb3 values ('a','aa',''); insert into tb3 values ('b','bb','a'); insert into tb3 values ('c','cc','b'); commit; select t.name from tb3 join (select name,p_id from tb3) t on tb3.id=t.p_id; 這是版主想要的結果嗎
select id from table where parent_id='a' union select id from table where parent_id in (select id from table where parent_id='a') 不知道符合不符合你的要求,当然这个语句速度会慢!
这两个语句可以满足你的要求: 1。select * from tableName start with ID=10 connect by prior parentID = ID 2。select * from tableName start with parentID =10 connect by prior parentID = ID1为往前找父记录;2为往后找子记录.
select id,name,p_id from (select id,name,p_id from test ) a start with p_id = 'a' connect by prior a.id = a.p_id order by p_id;
constraint pk_tb3id primary key (id));insert into tb3 values ('a','aa','');
insert into tb3 values ('b','bb','a');
insert into tb3 values ('c','cc','b');
commit;
select t.name from tb3 join (select name,p_id from tb3) t on tb3.id=t.p_id;
這是版主想要的結果嗎
union
select id from table where parent_id in (select id from table where parent_id='a')
不知道符合不符合你的要求,当然这个语句速度会慢!
1。select * from tableName start with ID=10 connect by prior parentID = ID
2。select * from tableName start with parentID =10 connect by prior parentID = ID1为往前找父记录;2为往后找子记录.