Solved

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

Posted on 2004-04-22
5
154 Views
Last Modified: 2010-04-01
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?

0
Comment
Question by:chambers777
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10893907
I don't get it..!!
what do you mean by second level???
0
 

Author Comment

by:chambers777
ID: 10893940
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....
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10894034
try
SELECT * from table where id IN (select id from table where parent_id=null)
0
 
LVL 19

Accepted Solution

by:
Kuldeepchaturvedi earned 50 total points
ID: 10894044
ooops sorry
SELECT * from table where parent_id IN (select id from table where parent_id=null)
0
 

Author Comment

by:chambers777
ID: 10894068
I SEE!
what about a third level?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question