Solved

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

Posted on 2004-04-22
5
156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 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