Link to home
Start Free TrialLog in
Avatar of chambers777
chambers777

asked on

How to select from DB all records on a certain recursive level

I have a db table like this for a site menu:

site_area
----------------------
id
name
parent_id


How to I select all records that exist on say, the 2nd level?

Avatar of Kuldeepchaturvedi
Kuldeepchaturvedi
Flag of United States of America image

I don't get it..!!
what do you mean by second level???
Avatar of chambers777
chambers777

ASKER

There will be a list of values where parent_id will be null.... they are the top level.

There will be a nother list that has parent_id as the id of a record with a null parent_id (this is the second level)... and so on....
try
SELECT * from table where id IN (select id from table where parent_id=null)
ASKER CERTIFIED SOLUTION
Avatar of Kuldeepchaturvedi
Kuldeepchaturvedi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I SEE!
what about a third level?