SQL Language (MOSC)

MOSC Banner

having level and wanting to find parent ID

edited Sep 26, 2011 6:56AM in SQL Language (MOSC) 10 commentsAnswered ✓
Hi,I got this table and data as follows,

CREATE TABLE test (seq NUMBER, nest NUMBER);
INSERT INTO test VALUES(1,1);
INSERT INTO test VALUES(2,2);
INSERT INTO test VALUES(3,3);
INSERT INTO test VALUES(4,3);
INSERT INTO test VALUES(5,1);
INSERT INTO test VALUES(6,2);
INSERT INTO test VALUES(7,2);
INSERT INTO test VALUES(8,3);
INSERT INTO test VALUES(9,3);
COMMIT;
SELECT * FROM test ORDER BY seq;
SEQ NEST
  1    1
  2    2
  3    3
  4    3
  5    1
  6    2
  7    2
  8    3
  9    3

I would like to develop a query to produce the following result set.
SEQ NEST  PARENT_SEQ
  1    1        NULL  
  2    2           1
  3    3           2
  4    3           2
  5    1        NULL
  6    2           5
  7    2           5
  8    3           7
  9    4           8

Any idea is appreciated.
Thanks,
Sha

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center