Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 19th, 2004, 02:24 PM
szadkowski szadkowski is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 5 szadkowski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old October 19th, 2004, 05:21 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
Code:
SELECT *
FROM TableName
WHERE ParentID = OrgID

Reply With Quote
  #3  
Old October 19th, 2004, 06:04 PM
Leslie's Avatar
Leslie Leslie is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Honolulu
Posts: 184 Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 29 m 2 sec
Reputation Power: 9
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!

Reply With Quote
  #4  
Old October 19th, 2004, 07:24 PM
szadkowski szadkowski is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 5 szadkowski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by Memnoch
Code:
SELECT *
FROM TableName
WHERE ParentID = OrgID


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.

Reply With Quote
  #5  
Old October 19th, 2004, 08:04 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,781 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 45 m 55 sec
Reputation Power: 470
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)

Reply With Quote
  #6  
Old October 19th, 2004, 10:05 PM
szadkowski szadkowski is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 5 szadkowski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Select to check id with parent id in same table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT