|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Select to check id with parent id in same table
Example:
org_id parent_id = the id value of another row in table I was wondering if there's a select or any other way for me to Open a table display an entry and all the entries with a parent id equal to the org_id |
|
#2
|
||||
|
||||
|
Code:
SELECT * FROM TableName WHERE ParentID = OrgID |
|
#3
|
||||
|
||||
|
Hang in there though, SQL 2005 may hopefully address the parent/child issue with an answer to Oracles CONNECT BY statement, and if so, you will be able to select the entire table and return all children. The statement provided above only works for a specific parent id for one level of children which may be all you need for this particular problem but it is likely this issue will resurface again in your future one day if you continue developing.
An old problem with no new solutions from Microsoft As it is, we programmers have to manually code functions to loop the table and keep track of the children as we go. This is one of few things I like better in Oracle. Good luck! |
|
#4
|
|||
|
|||
|
Quote:
There's no problem there, but my problem is that How do i display all the child rows when i'm displaying the parent rows. ie parent display AB child display 1 AB child display 2 AB parent display CD child display 1 CD there has to be a way to do it will sub query's but i just can't get it to work. |
|
#5
|
||||
|
||||
|
Try inner joining the table on itself to return the child rows.
Code:
SELECT A.*, B.* FROM TableName As A INNER JOIN TableName As B On (A.ParentID = B.OrgID) |
|
#6
|
|||
|
|||
|
thanks.
|
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Select to check id with parent id in same table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|