Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-22
5
Medium Priority
?
159 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

610 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