Re: Query to show last time someone logged in.
- From: John Vinson <jvinson@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 24 May 2005 23:15:10 -0600
On Tue, 24 May 2005 21:34:02 -0700, "Jonathan Brown"
<JonathanBrown@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>When my users log into my database a query automatically runs and creates a
>new record in a table called tblUsageStats. Each record contains the user's
>Username and the Current date & time (Now()).
>
>I want to create a query now that will pull from that table only the last
>time each user logged in. So it would probably looks something like:
>
>FROM "tblUsageStats"
>Select "Username" & "Date"
>Where "Date" = "The last time they logged in" or "The closest date to NOW()"
>
>This is not to say, "Who was the last person to login?" but "when was the
>last time each user logged in?"
>
>Thanks a ton.
A Subquery will do this:
SELECT [Username], [Date]
FROM [tblUsageStats]
WHERE [Date] = (SELECT Max([Date]) FROM tblUsageStats AS X
WHERE X.[Username] = [tblUsageStats].[Username]);
Note that fieldnames must be delimited with [brackets] not "quotes",
or you'll retrieve the literal string values "Username" and "Date".
Also, the field named Date should be renamed - that's a reserved word
and very well may cause problems.
John W. Vinson[MVP]
.
- Follow-Ups:
- Re: Query to show last time someone logged in.
- From: Jonathan Brown
- Re: Query to show last time someone logged in.
- References:
- Query to show last time someone logged in.
- From: Jonathan Brown
- Query to show last time someone logged in.
- Prev by Date: Re: Build a query that meets a calcuated field and another criteria
- Next by Date: Re: Adding Prefix to multiple rows n Access? Help!
- Previous by thread: Query to show last time someone logged in.
- Next by thread: Re: Query to show last time someone logged in.
- Index(es):
Relevant Pages
|