More help with returning the newest record in a query
  Home FAQ Contact Sign in
microsoft.public.access.queries only
 
Advanced search
POPULAR GROUPS

more...

microsoft ... access.queries Profile…
 Up
More help with returning the newest record in a query         


Author: JessM
Date: Aug 8, 2008 21:36

I have a form that comments can be entered into and receive a time stamp. So
I end up with multiple comments per project number. I want to run a query
that only returns the newest comment for each project number.

Below is what I tried, but I get the following error message: The LEVEL
clause includes a word or argument that is misspelled or missing,
or the punctuation is incorrrect.

New Query:
SELECT Data_ProjectComments.Project_Number,
Data_ProjectComments.CurrentTime, Data_ProjectComments.CommentCode,
Data_ProjectComments.Comment
FROM Data_ProjectComments
WHERE (((Data_ProjectComments.CurrentTime)=(SELECT MAX(CurrentTime) FROM
Data_ProjectComments)));
Group By Data_ProjectComments.Project_Number
6 Comments
RE: More help with returning the newest record in a query         


Author: KARL DEWEY
Date: Aug 8, 2008 22:00

Subqueries do not end with a semicolon. Try it this way ---
SELECT Data_ProjectComments.Project_Number,
Data_ProjectComments.CurrentTime, Data_ProjectComments.CommentCode,
Data_ProjectComments.Comment
FROM Data_ProjectComments
WHERE (((Data_ProjectComments.CurrentTime)=(SELECT MAX(CurrentTime) FROM
Data_ProjectComments)))
Group By Data_ProjectComments.Project_Number;

--
KARL DEWEY
Build a little - Test a little

"JessM" wrote:
Show full article (1.20Kb)
no comments
RE: More help with returning the newest record in a query         


Author: KARL DEWEY
Date: Aug 8, 2008 22:14

Try it this way ---
SELECT Data_ProjectComments.Project_Number,
Data_ProjectComments.CurrentTime, Data_ProjectComments.CommentCode,
Data_ProjectComments.Comment
FROM Data_ProjectComments
WHERE (((Data_ProjectComments.CurrentTime)=(SELECT MAX(CurrentTime) FROM
Data_ProjectComments)))
Group By Data_ProjectComments.Project_Number,
Data_ProjectComments.CurrentTime, Data_ProjectComments.CommentCode,
Data_ProjectComments.Comment;

--
KARL DEWEY
Build a little - Test a little

"JessM" wrote:
> I get the following error message when I try it:
>
> You tried to execute a query that does not inlcude the specifed expression
> 'CurrentTime' as part of an aggregate function.
>
>
>
>
>
> "KARL...
Show full article (2.06Kb)
no comments
RE: More help with returning the newest record in a query         


Author: JessM
Date: Aug 8, 2008 22:19

It works but it only gives me the most recent project number comment overall,
it doesn't give me the most recent comment for each project number.

"KARL DEWEY" wrote:
> Try it this way ---
> SELECT Data_ProjectComments.Project_Number,
> Data_ProjectComments.CurrentTime, Data_ProjectComments.CommentCode,
> Data_ProjectComments.Comment
> FROM Data_ProjectComments
>...
Show full article (2.35Kb)
no comments
RE: More help with returning the newest record in a query         


Author: JessM
Date: Aug 8, 2008 22:39

I get the following error message when I try it:

You tried to execute a query that does not inlcude the specifed expression
'CurrentTime' as part of an aggregate function.

"KARL DEWEY" wrote:
> Subqueries do not end with a semicolon. Try it this way ---
> SELECT Data_ProjectComments.Project_Number,
> Data_ProjectComments.CurrentTime, Data_ProjectComments.CommentCode,
> Data_ProjectComments...
Show full article (1.47Kb)
no comments
RE: More help with returning the newest record in a query         


Author: KARL DEWEY
Date: Aug 9, 2008 00:09

I do not know sub queries so I used two ---
Data_ProjectComments_Latest ---
SELECT Data_ProjectComments.Project_Number,
Max(Data_ProjectComments.CurrentTime) AS MaxOfCurrentTime
FROM Data_ProjectComments
GROUP BY Data_ProjectComments.Project_Number;

SELECT Data_ProjectComments.Project_Number,
Data_ProjectComments.CurrentTime, Data_ProjectComments.CommentCode,
Data_ProjectComments.Comment
FROM Data_ProjectComments INNER JOIN Data_ProjectComments_Latest ON
(Data_ProjectComments.CurrentTime =
Data_ProjectComments_Latest.MaxOfCurrentTime) AND
(Data_ProjectComments.Project_Number =
Data_ProjectComments_Latest.Project_Number);

--
KARL DEWEY
Build a little - Test a little

"JessM" wrote:
> It works but it only gives me the most recent project number comment overall,
> it doesn't give me the most recent comment for each project number.
>
> "KARL DEWEY" wrote:
>
>> Try it this way -...
Show full article (3.20Kb)
no comments
RE: More help with returning the newest record in a query         


Author: JessM
Date: Aug 11, 2008 15:08

Thanks - that worked!!

"KARL DEWEY" wrote:
> I do not know sub queries so I used two ---
> Data_ProjectComments_Latest ---
> SELECT Data_ProjectComments.Project_Number,
> Max(Data_ProjectComments.CurrentTime) AS MaxOfCurrentTime
> FROM Data_ProjectComments...
Show full article (3.42Kb)
no comments