| Author |
Topic |
|
LearnEveryDay
Starting Member
37 Posts |
Posted - 2005-09-15 : 09:02:19
|
| Hi GuysThis is my tableID name ParentID------------------------------1 TestParent1 <null>2 TestChid1 13 TestChild2 14. TestParent2 <null>5 TestParent3 <null>6 TestParent 4 <null>7 TestChild3 68 TestChild4 6basically I want to get records from the above table those who does not have child. In the above caseI want records like 4. TestParent2 <null>5 TestParent3 <null>How would i write the sql query to get it worked??Cheers, |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-09-15 : 09:18:29
|
Is this what you're looking for?select [Columns I want]from [my table]where ParentID is NULL Be One with the OptimizerTG |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-09-15 : 09:18:44
|
Select A.* From <yourTable> ALeft Join <yourTable> BOn A.id = B.parentIdWhere B.id is nullCorey Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now." |
 |
|
|
LearnEveryDay
Starting Member
37 Posts |
Posted - 2005-09-15 : 09:20:58
|
| No..no..noWell, the table has got some parents with children and some does not.I want parent records which does not have any children.Can i do it as a simple query or do i need to write cursor??cheers, |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-09-15 : 09:21:01
|
| Dang! I forgot to read the question before answering again...sigh...Be One with the OptimizerTG |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-09-15 : 09:31:41
|
| How do you expect these from your sample data?4. TestParent2 <null>5 TestParent3 <null>MadhivananFailing to plan is Planning to fail |
 |
|
|
LearnEveryDay
Starting Member
37 Posts |
Posted - 2005-09-15 : 09:38:27
|
| Hi,I am just working on a simple web project with parent and child technique.and I am simply trying to make a parent which does not have any child, as a child to another parent. I thought it might be beyond my knowledge, but it makes sense doesn't it?. if a parent does not have a child why can't i use that parent to another parent's child.May be my thought is wrong. but please explain me...... |
 |
|
|
LearnEveryDay
Starting Member
37 Posts |
Posted - 2005-09-15 : 09:41:45
|
quote: Originally posted by madhivanan How do you expect these from your sample data?4. TestParent2 <null>5 TestParent3 <null>MadhivananFailing to plan is Planning to fail
I can see those two records does not have any child ;) |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-09-15 : 09:51:48
|
read my post -^I gave you the query to find parent's with no children...as far as:quote: if a parent does not have a child why can't i use that parent to another parent's child.
how do you distinguish if:The parent is a parent without a child, that the child of the parent is not really the child but is the child of a different parent Corey Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now." |
 |
|
|
Stalker
Yak Posting Veteran
80 Posts |
Posted - 2005-09-15 : 10:19:19
|
| select distinct id_ from treetable where id_ not in (select parent from treetable) |
 |
|
|
LearnEveryDay
Starting Member
37 Posts |
Posted - 2005-09-15 : 11:04:24
|
quote: Originally posted by Seventhnight read my post -^I gave you the query to find parent's with no children...
Thanks seventhlight it works alright. Thanks a lot.Cheers, |
 |
|
|
|