Ray Cheng
Ray Cheng

Reputation: 12576

Order by parent

I have a STUDENT table:

with data:

54, 99
50, null
5, 54,
99, 50

How can I query them in this order?

50 <-- first, because it has no parent, so it's root
99 <-- second, because it's parent is the root item
54 <-- third, because it's parent is the second item
5  <-- forth, because it's parent is the third item

Upvotes: 1

Views: 54

Answers (1)

Mark J. Bobak
Mark J. Bobak

Reputation: 14395

You need a CONNECT BY clause.

See the SQL Fiddle.

Upvotes: 5

Related Questions