Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
English
GROUP BY to extract the most oldest record
Message
From
04/01/2003 15:46:18
 
General information
Fórum:
Visual FoxPro
Category:
Bases de dados, Tabelas, Views, Indices e SQL
Miscellaneous
ID da thread:
00738069
ID da mensagem:
00738073
Views:
25
>Try
SELECT * FROM mytable m1
>  WHERE UniqueId IN
>    ( SELECT MIN(UniqueId) FROM mytable m2 WHERE m2.GroupField = m2.GroupField )
>
Or
SELECT MIN(UniqueId) AS UniqueId, GroupField1, GroupField2 ;
>  FROM mytable
>  GROUP BY GroupField1, GroupField2 ;
>  INTO CURSOR crsMin
>
>SELECT *  ;
>  FROM mytable
>  WHERE UniqueId + GroupField1 + GroupField2 IN ( ;
>    SELECT UniqueId + GroupField1 + GroupField2 FROM crsMin ) ;
>  INTO CURSOR crsResult
>
Yes, as I need additional fields and they should match the record that has been selected, I need to do that in two steps. Either such as you did or doing a small scan after to adjust some fields.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Responder
Mapa
View

Click here to load this message in the networking platform