Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
V6s5 - SQL for Parent and only the Latest Child rec
Message
From
29/03/2004 05:02:07
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00888750
Message ID:
00890363
Views:
24
>Hi Cetin
>
>>You don't need to group by but be careful this is not the same with the one we suggested.
>>
>>
SELECT tNonCummu.*, sNonCummu.*
>>    FROM tNonCummu
>>       JOIN sNonCummu ON tNonCummu.iID = sNonCummu.iPID
>>    WHERE sNonCummu.dDueDt =
>>       (SELECT MAX(sNC.dDueDt)
>>          FROM sNonCummu sNC where sNonCummu.iPID = sNC.iPID )
Cetin
>
>The original returned only one record between all parent so I added the GROUP BY, thus getting one for each parent, did I mess up somewhere? I'll try them both again.

In pseudocode it's like :

Select distinct values
while selecting
select the record with the latest date and populate related fields from that record

>> WHERE sNonCummu.dDueDt =
>> (SELECT MAX(sNC.dDueDt)
>> FROM sNonCummu sNC where sNonCummu.iPID = sNC.iPID )

Tells to find latest date for 'current of' iPID.
= works as subquery returns a single value.

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform