Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Other SQL Server Topics / May 2008

Tip: Looking for answers? Try searching our database.

Get last child of parents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LVP - 28 May 2008 02:11 GMT
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
Linchi Shea - 28 May 2008 03:58 GMT
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

> I have the need to get the last child of each parent.
>
[quoted text clipped - 12 lines]
>
> LVP
LVP - 28 May 2008 18:02 GMT
Linchi,

Thanks for your help, I got the same answer that works from another NG.

Thanks again,

LVP

> select c.c1_id, c.pk1_id
>  from Child c join (
[quoted text clipped - 22 lines]
>>
>> LVP
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.