Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MAX() group by in SQL?
Message
 
 
To
01/11/2004 16:51:14
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8
OS:
Windows 2000 SP3
Network:
Windows NT
Database:
Visual FoxPro
Miscellaneous
Thread ID:
00956733
Message ID:
00956744
Views:
7
Tom,

Try (assuming that 'act_dt' is unique per 'id')
SELECT id, act_dt, col3, col4 ;
  FROM tbl t1
  WHERE act_dt = (SELECT MAX(act_dt) FROM tbl t2 WHERE t1.id = t2.id)
>I need to do a SQL SELECT that keeps the ID and I need the last action date. The code to do that is as follows:
>
>SELECT id, MAX(act_dt) FROM tbl GROUP BY id
>
>OK, so far no problem. However, what if there are 10 action dates per ID and I also need to keep two more columns? That is, I need the exact values for the other two columns that correspond to the same row that is on the MAX(act_dt).
>
>How can I be sure that I am getting say row 8 as the MAX date and the other two columns associated with that MAX date are also from the same row 8 not row 1 or 4 or 10?
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform