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?
site_area
----------------------
id
name
parent_id
How to I select all records that exist on say, the 2nd level?
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....
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)
SELECT * from table where id IN (select id from table where parent_id=null)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I SEE!
what about a third level?
what about a third level?
what do you mean by second level???