Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GROUP BY to extract the most oldest record
Message
 
 
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:
00738072
Views:
18
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
>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.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform