Re: Limit query results to 1 item
- From: John Spencer <spencer@xxxxxxxxxx>
- Date: Mon, 07 Apr 2008 20:21:26 -0400
Perhaps something like the following will work for you. You may need to expand the where clause in the subquery to include the all or part of the other criteria you have specified for the main query.
SELECT tblFullSelectInfo.Name
, tblFullSelectInfo.DateSelected
, tblFullSelectInfo.Rank
, tblFullSelectInfo.SSN
, tblFullSelectInfo.Notes
, tblFullSelectInfo.WorkCenter
, tblFullSelectInfo.WorkPhone
, tblFullSelectInfo.PendingPool
, tblFullSelectInfo.DueDate
, tblFullSelectInfo.CompleteDate
FROM tblFullSelectInfo INNER JOIN
(SELECT T.Name, Max(DateSelected) as LastDate
FROM tblFullSelectInfo as T
WHERE T.DateSelected >= Date() -30
GROUP BY T.Name) as TheLast
ON tblFullSelectInfo.Name = TheLast.Name
AND tblFullSelectInfo.DateSelected = TheLast.LastDate
WHERE tblFullSelectInfo.DateSelected>=Date()-30
AND tblFullSelectInfo.Notes Not Like "not in *"
AND tblFullSelectInfo.Notes Not Like "PCS*"
AND tblFullSelectInfo.CompleteDate Is Null
ORDER BY tblFullSelectInfo.DateSelected DESC;
'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
Valix wrote:
Thanks for the info on that, but Im still having an issue. I can see where that will give me the latest date, but it knocks out alot of records. what I am looking for is a way to show me the latest date for each person, not just the people with the latest date for all records..
example: When i run the report/query normal, i get 8 pages of people with numerous dates showing no completion, say most with selection date of 31 Mar 08. When I added the TOP 1 to the SELECT statement, i got 4 records returned with the date selected of 4 Apr 08, because that is the latest date input into my database.
If I have 30 people on my report with 3-4 dates each, how do I get it to show 30 people, but only their latest date selected?
thanks again
"Armen Stein" wrote:
On Mon, 7 Apr 2008 12:20:04 -0700, Valix
<Valix@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
SELECT tblFullSelectInfo.Name, tblFullSelectInfo.DateSelected, tblFullSelectInfo.Rank, tblFullSelectInfo.SSN, tblFullSelectInfo.Notes, tblFullSelectInfo.WorkCenter, tblFullSelectInfo.WorkPhone, tblFullSelectInfo.PendingPool, tblFullSelectInfo.DueDate, tblFullSelectInfo.CompleteDate>FROM tblFullSelectInfoWHERE (((tblFullSelectInfo.DateSelected)>=Date()-30) AND ((tblFullSelectInfo.Notes) Not Like "not in *" AND (tblFullSelectInfo.Notes) Not Like "PCS*") AND ((tblFullSelectInfo.CompleteDate) Is Null))Try adding TOP 1 to your Select statement.
ORDER BY tblFullSelectInfo.DateSelected DESC;
I am running 3 query's like above based on 7, 30 and 90 days. When I run this, I get multiple results for some people due to multiple entries when selected with no completion date. But what I am looking for is the query results to only show me the latest date selected with no completion date, one result. I do have a report built to show these results, but how do I go about limiting the results to just the one.
Thanks for any info, hope Im not confusing (maybe just myself).
Armen Stein
Microsoft Access MVP
www.JStreetTech.com
- Follow-Ups:
- Re: Limit query results to 1 item
- From: Valix
- Re: Limit query results to 1 item
- References:
- Limit query results to 1 item
- From: Valix
- Re: Limit query results to 1 item
- From: Armen Stein
- Re: Limit query results to 1 item
- From: Valix
- Limit query results to 1 item
- Prev by Date: Re: How do I set up a parameter query in a cross tabs query?
- Next by Date: creating a custom date from two "between..and" dates
- Previous by thread: Re: Limit query results to 1 item
- Next by thread: Re: Limit query results to 1 item
- Index(es):
Relevant Pages
|