Home » SQL & PL/SQL » SQL & PL/SQL » Sql Query
icon2.gif  Sql Query [message #247816] Wed, 27 June 2007 05:16 Go to next message
balaji23_d
Messages: 123
Registered: February 2007
Senior Member

Hi all,

I have a table "Users" based on Parent-Child Relationship,
This table has columns "UserID, ParentID, LeftChild, RightChild"

Data in this table like
UserID ParentID LeftChild RightChild
1       null    2         3
2        1      4         6
3        1      5         7
4        2      8         null
5        3      null      null
6        2      null      9
7        3      null      null
8        4      10        null
9        6      null      null
10       8      null      null


I want to find records of all childrens for a particular parent using SQL Query
suppose find for userid=2,

2 have two childrens 4 and 6
now 4 has 8 and 8 has 10
6 has 9 and so on

so ans for userid =2 are as below
4
6
8
9
10

please write the query.. for this

Thanks and regrads

[Updated on: Wed, 27 June 2007 05:21] by Moderator

Report message to a moderator

Re: Sql Query [message #247819 is a reply to message #247816] Wed, 27 June 2007 05:21 Go to previous messageGo to next message
ebrian
Messages: 2794
Registered: April 2006
Senior Member
What have you tried so far? Will another student allow you to see what they got for this homework assignment?

You need to read the stickies in this forum!
Re: Sql Query [message #247825 is a reply to message #247819] Wed, 27 June 2007 05:43 Go to previous messageGo to next message
caliguardo
Messages: 107
Registered: February 2007
Location: Chennai
Senior Member

Try using start with ,connect by prior.
Go through hierarchial queries.
Re: Sql Query [message #247868 is a reply to message #247816] Wed, 27 June 2007 07:11 Go to previous messageGo to next message
balaji23_d
Messages: 123
Registered: February 2007
Senior Member
thank u cali

If possible,Please write the query and submit in this forum...
Re: Sql Query [message #247875 is a reply to message #247816] Wed, 27 June 2007 07:35 Go to previous messageGo to next message
MarcL
Messages: 455
Registered: November 2006
Location: Connecticut, USA
Senior Member
You really expect us to do your work without you even trying ?

Show us what you have tried and what errors you are getting.

If you want to hire one of us on as a consultant we'd be happy to write your code for you.

Re: Sql Query [message #247882 is a reply to message #247816] Wed, 27 June 2007 07:44 Go to previous messageGo to next message
balaji23_d
Messages: 123
Registered: February 2007
Senior Member

Hi marcl,

Is it correct?
I tried this query.. but i cant access the database here...because some restrictions here to be accesing the database..If wrong, pls mention and revert back to me


select UserId from Users start with ParentID = 2 connect by ParentID = prior UserId
Re: Sql Query [message #247887 is a reply to message #247816] Wed, 27 June 2007 07:49 Go to previous message
MarcL
Messages: 455
Registered: November 2006
Location: Connecticut, USA
Senior Member
You're telling me that you are expected to write code and not have a database to test it against ?

Funny, in your OP you were able to extract the data.

If this is the case, you need to have a chat with your manager.

Good luck.

[Updated on: Wed, 27 June 2007 07:50]

Report message to a moderator

Previous Topic: Can not send mail thru pl/sql
Next Topic: Sql Query
Goto Forum:
  


Current Time: Sat Dec 10 20:27:53 CST 2016

Total time taken to generate the page: 0.04260 seconds