Solved

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

Posted on 2004-04-22
5
152 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now