Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 How to get the newest DateTime

Author  Topic 

Freak
Starting Member

3 Posts

Posted - 2008-07-09 : 07:57:19
Hi,

this is my table in MS Access 2003:

Name_ Date_

John 6/12/2008 10:00:00
John 6/14/2008 09:45:00
Mike 5/10/2008 01:30:00
Mike 7/7/2008 04:40:00

Name_ is Text and Date_ is DateTime. None is Primay Key.

How to get this result:

John 6/14/2008 09:45:00
Mike 7/7/2008 04:40:00

Name of the people which Date_ is the "newest" of all in table.
I tried like this:

select Name_,Date_ from Logs
Grup by Name_, Date_
HAVING MAX(Date_); but it doesn't work.

Freak
Starting Member

3 Posts

Posted - 2008-07-09 : 08:00:25
This work but only for one Name:

select Name_, Date_
from Logs
Where Name_ LIKE "Mike"
Group by Name_, Date_
HAVING MAX(Date_);
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-07-09 : 08:14:27
Just the maximum date for each person in the table?

try...

SELECT
[name_]
, MAX([date_])
FROM
Logs
GROUP BY
[name_]


-------------
Charlie
Go to Top of Page

Freak
Starting Member

3 Posts

Posted - 2008-07-09 : 08:53:53
Transact Charlie thanks a lot. I owe you a beer.
I found this also:

GROUP BY... was added to SQL because aggregate functions (like SUM) return the aggregate of all column values every time they are called, and without the GROUP BY function it was impossible to find the sum for each individual group of column values.
Go to Top of Page
   

- Advertisement -