Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GROUP BY to extract the most oldest record
Message
From
06/01/2003 06:05:02
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
04/01/2003 15:31:47
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00738069
Message ID:
00738333
Views:
14
>I have a SQL which contains a GROUP BY clause. For the record that will be extract for each group, I need to extract the oldest one. I have a primary field that could be used for that. Basically, the lowest value in the primary field determines the first record that was created in that group. I'm trying to find the best approach in the SQL to achieve that.

Group by pkfield ?
select * from myTable A where datefield = ;
 (select min(datefield) from myTable B where a.pkfield = b.pkfield) ;
 order by pkfield
If no datetimefield or such (physically entered first is oldest) - requires 70 compatibility in VFP8 :
select *,sys(2015) as dummyorder ;
 from myTable ;
 order by DummyOrder descending ;
 into cursor crsTemp nofilter

select .... from crStemp group by ....
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