私はこれを使用しました:
CREATE TABLE my_table(ID NUMBER, locid NUMBER, parentid NUMBER, filename VARCHAR2(10));
BEGIN
INSERT INTO my_table VALUES(1,1,0,'word');
INSERT INTO my_table VALUES(2,1,0,'excel');
INSERT INTO my_table VALUES(3,1,1,'power');
INSERT INTO my_table VALUES(4,2,0,'word');
INSERT INTO my_table VALUES(5,2,4,'power');
END;
/
通常の方法は:
SELECT * FROM my_table;
select * from my_table where parentid=0;
SELECT distinct t1.ID, t1.locid, t1.parentid, t1.filename FROM my_table t1
JOIN my_table t2 ON t1.parentid = t2.parentid AND t2.parentid = 0;
結果は次のようになります。
1 1 0 word
2 1 0 excel
4 2 0 word