dbTalk Databases Forums  

Get last child of parents

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss Get last child of parents in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
LVP
 
Posts: n/a

Default Get last child of parents - 05-27-2008 , 08:11 PM






I have the need to get the last child of each parent.

Note: eDate if what points me to the Last child not the c1_id

Parent ( pk1_id , etc..)

Child ( c1_id, pk1.id, eDate, type_id)


Need the pattern to do this

tried max(), top 1 etc.. just can not figure it out. been driving me nuts
for half an hour.

Thanks

LVP


Reply With Quote
  #2  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Get last child of parents - 05-27-2008 , 09:58 PM






select c.c1_id, c.pk1_id
from Child c join (
select p.pk1_id, max(c1.eDate) as eDate
from Parent p join Child c1 on p.pk1_id = c1.pk1_id
group by p.pk1_id ) as t
on c.pk1_id = t.pk1_id and c.eDate = t.eDate

Linchi

"LVP" wrote:

Quote:
I have the need to get the last child of each parent.

Note: eDate if what points me to the Last child not the c1_id

Parent ( pk1_id , etc..)

Child ( c1_id, pk1.id, eDate, type_id)


Need the pattern to do this

tried max(), top 1 etc.. just can not figure it out. been driving me nuts
for half an hour.

Thanks

LVP


Reply With Quote
  #3  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Get last child of parents - 05-27-2008 , 09:58 PM



select c.c1_id, c.pk1_id
from Child c join (
select p.pk1_id, max(c1.eDate) as eDate
from Parent p join Child c1 on p.pk1_id = c1.pk1_id
group by p.pk1_id ) as t
on c.pk1_id = t.pk1_id and c.eDate = t.eDate

Linchi

"LVP" wrote:

Quote:
I have the need to get the last child of each parent.

Note: eDate if what points me to the Last child not the c1_id

Parent ( pk1_id , etc..)

Child ( c1_id, pk1.id, eDate, type_id)


Need the pattern to do this

tried max(), top 1 etc.. just can not figure it out. been driving me nuts
for half an hour.

Thanks

LVP


Reply With Quote
  #4  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Get last child of parents - 05-27-2008 , 09:58 PM



select c.c1_id, c.pk1_id
from Child c join (
select p.pk1_id, max(c1.eDate) as eDate
from Parent p join Child c1 on p.pk1_id = c1.pk1_id
group by p.pk1_id ) as t
on c.pk1_id = t.pk1_id and c.eDate = t.eDate

Linchi

"LVP" wrote:

Quote:
I have the need to get the last child of each parent.

Note: eDate if what points me to the Last child not the c1_id

Parent ( pk1_id , etc..)

Child ( c1_id, pk1.id, eDate, type_id)


Need the pattern to do this

tried max(), top 1 etc.. just can not figure it out. been driving me nuts
for half an hour.

Thanks

LVP


Reply With Quote
  #5  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Get last child of parents - 05-27-2008 , 09:58 PM



select c.c1_id, c.pk1_id
from Child c join (
select p.pk1_id, max(c1.eDate) as eDate
from Parent p join Child c1 on p.pk1_id = c1.pk1_id
group by p.pk1_id ) as t
on c.pk1_id = t.pk1_id and c.eDate = t.eDate

Linchi

"LVP" wrote:

Quote:
I have the need to get the last child of each parent.

Note: eDate if what points me to the Last child not the c1_id

Parent ( pk1_id , etc..)

Child ( c1_id, pk1.id, eDate, type_id)


Need the pattern to do this

tried max(), top 1 etc.. just can not figure it out. been driving me nuts
for half an hour.

Thanks

LVP


Reply With Quote
  #6  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Get last child of parents - 05-27-2008 , 09:58 PM



select c.c1_id, c.pk1_id
from Child c join (
select p.pk1_id, max(c1.eDate) as eDate
from Parent p join Child c1 on p.pk1_id = c1.pk1_id
group by p.pk1_id ) as t
on c.pk1_id = t.pk1_id and c.eDate = t.eDate

Linchi

"LVP" wrote:

Quote:
I have the need to get the last child of each parent.

Note: eDate if what points me to the Last child not the c1_id

Parent ( pk1_id , etc..)

Child ( c1_id, pk1.id, eDate, type_id)


Need the pattern to do this

tried max(), top 1 etc.. just can not figure it out. been driving me nuts
for half an hour.

Thanks

LVP


Reply With Quote
  #7  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Get last child of parents - 05-27-2008 , 09:58 PM



select c.c1_id, c.pk1_id
from Child c join (
select p.pk1_id, max(c1.eDate) as eDate
from Parent p join Child c1 on p.pk1_id = c1.pk1_id
group by p.pk1_id ) as t
on c.pk1_id = t.pk1_id and c.eDate = t.eDate

Linchi

"LVP" wrote:

Quote:
I have the need to get the last child of each parent.

Note: eDate if what points me to the Last child not the c1_id

Parent ( pk1_id , etc..)

Child ( c1_id, pk1.id, eDate, type_id)


Need the pattern to do this

tried max(), top 1 etc.. just can not figure it out. been driving me nuts
for half an hour.

Thanks

LVP


Reply With Quote
  #8  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Get last child of parents - 05-27-2008 , 09:58 PM



select c.c1_id, c.pk1_id
from Child c join (
select p.pk1_id, max(c1.eDate) as eDate
from Parent p join Child c1 on p.pk1_id = c1.pk1_id
group by p.pk1_id ) as t
on c.pk1_id = t.pk1_id and c.eDate = t.eDate

Linchi

"LVP" wrote:

Quote:
I have the need to get the last child of each parent.

Note: eDate if what points me to the Last child not the c1_id

Parent ( pk1_id , etc..)

Child ( c1_id, pk1.id, eDate, type_id)


Need the pattern to do this

tried max(), top 1 etc.. just can not figure it out. been driving me nuts
for half an hour.

Thanks

LVP


Reply With Quote
  #9  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Get last child of parents - 05-27-2008 , 09:58 PM



select c.c1_id, c.pk1_id
from Child c join (
select p.pk1_id, max(c1.eDate) as eDate
from Parent p join Child c1 on p.pk1_id = c1.pk1_id
group by p.pk1_id ) as t
on c.pk1_id = t.pk1_id and c.eDate = t.eDate

Linchi

"LVP" wrote:

Quote:
I have the need to get the last child of each parent.

Note: eDate if what points me to the Last child not the c1_id

Parent ( pk1_id , etc..)

Child ( c1_id, pk1.id, eDate, type_id)


Need the pattern to do this

tried max(), top 1 etc.. just can not figure it out. been driving me nuts
for half an hour.

Thanks

LVP


Reply With Quote
  #10  
Old   
Linchi Shea
 
Posts: n/a

Default RE: Get last child of parents - 05-27-2008 , 09:58 PM



select c.c1_id, c.pk1_id
from Child c join (
select p.pk1_id, max(c1.eDate) as eDate
from Parent p join Child c1 on p.pk1_id = c1.pk1_id
group by p.pk1_id ) as t
on c.pk1_id = t.pk1_id and c.eDate = t.eDate

Linchi

"LVP" wrote:

Quote:
I have the need to get the last child of each parent.

Note: eDate if what points me to the Last child not the c1_id

Parent ( pk1_id , etc..)

Child ( c1_id, pk1.id, eDate, type_id)


Need the pattern to do this

tried max(), top 1 etc.. just can not figure it out. been driving me nuts
for half an hour.

Thanks

LVP


Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.