Solved

Return only latest status update in query

Posted on 2014-04-07
3
263 Views
Last Modified: 2014-04-08
Hi.  I am using Access 2010 and trying to create a query that will return only the most recent status update for a project.
Here's the sql for the query.

SELECT DISTINCT qryProjectID.ProjID, tblStatus.StatusDate, Max(tblStatus.StatusDate) AS LatestDate
FROM qryProjectID INNER JOIN tblStatus ON qryProjectID.ProjID = tblStatus.ProjectID
GROUP BY qryProjectID.ProjID, tblStatus.StatusDate;
picture of resultsThis is the result I get.  I want Project 1 only once and showing the last status update date.  Suggestions anyone?

Tables are tblProject with ProjID and tblStatus with ProjectID, StatusID, StatusDate, and other detail fields.  Tables are joined one to many from tblProject to tblStatus.
0
Comment
Question by:esbyrt
3 Comments
 
LVL 35

Expert Comment

by:PatHartman
ID: 39984595
Remove the Distinct predicate.  It is interfering with the grouping.
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 39984680
if you want the project just once then remove  tblStatus.StatusDate as a column and in the group by

SELECT qryProjectID.ProjID,  Max(tblStatus.StatusDate) AS LatestDate
FROM qryProjectID INNER JOIN tblStatus ON qryProjectID.ProjID = tblStatus.ProjectID
GROUP BY qryProjectID.ProjID;

ps, never use select distinct when also doing a group by - it's a complete waste of time
0
 

Author Closing Comment

by:esbyrt
ID: 39987241
Worked like a dream!  Thank you!
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question