Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Access - Get latest DateAuthorized for each Emp_ID

Posted on 2012-09-18
3
Medium Priority
?
351 Views
Last Modified: 2012-09-18
Hello all

I am attempting to define a Many to Many table link and get a query of the latest DateAuthorized for each employee.

I've tried Last, Max etc.  but I really can't grasp it.

SELECT Link_EmpToActAuthLevel.Emp_ID, Link_EmpToActAuthLevel.ActAuthLevelID, Link_EmpToActAuthLevel.DateAuthorized, Link_EmpToActAuthLevel.LinkEmpToActAuthLevelID, qry_Employees.EmpFullName, qry_Employees.EmpFullNickname, ActivityAuthorizationLevel.ActAuthLevel
FROM ActivityAuthorizationLevel INNER JOIN (Link_EmpToActAuthLevel INNER JOIN qry_Employees ON Link_EmpToActAuthLevel.Emp_ID = qry_Employees.EmpID) ON ActivityAuthorizationLevel.ActAuthLevelID = Link_EmpToActAuthLevel.ActAuthLevelID
GROUP BY Link_EmpToActAuthLevel.Emp_ID, Link_EmpToActAuthLevel.ActAuthLevelID, Link_EmpToActAuthLevel.DateAuthorized, Link_EmpToActAuthLevel.LinkEmpToActAuthLevelID, qry_Employees.EmpFullName, qry_Employees.EmpFullNickname, ActivityAuthorizationLevel.ActAuthLevel;

Open in new window

0
Comment
Question by:wlwebb
  • 2
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 2000 total points
ID: 38410980
Save this as a query named qryInitial (or whatever name you want to give it):
SELECT Link_EmpToActAuthLevel.Emp_ID AS EmployeeID, Link_EmpToActAuthLevel.ActAuthLevelID, Link_EmpToActAuthLevel.DateAuthorized AS AuthorizationDate, Link_EmpToActAuthLevel.LinkEmpToActAuthLevelID, qry_Employees.EmpFullName, qry_Employees.EmpFullNickname, ActivityAuthorizationLevel.ActAuthLevel
FROM ActivityAuthorizationLevel INNER JOIN (Link_EmpToActAuthLevel INNER JOIN qry_Employees ON Link_EmpToActAuthLevel.Emp_ID = qry_Employees.EmpID) ON ActivityAuthorizationLevel.ActAuthLevelID = Link_EmpToActAuthLevel.ActAuthLevelID
GROUP BY Link_EmpToActAuthLevel.Emp_ID, Link_EmpToActAuthLevel.ActAuthLevelID, Link_EmpToActAuthLevel.DateAuthorized, Link_EmpToActAuthLevel.LinkEmpToActAuthLevelID, qry_Employees.EmpFullName, qry_Employees.EmpFullNickname, ActivityAuthorizationLevel.ActAuthLevel;

Open in new window



Then run this query to get your employeeID and latest date:

SELECT MAX(AuthorizationDate) AS MaxAuthDate, EmployeeID
FROM qryInitial
GROUP BY EmployeeID

Open in new window



Note:  I'm going on the assumption that the query you posted is a working query, and that you just want the EmployeeID and Max Authorization Date from it.
0
 
LVL 61

Assisted Solution

by:mbizup
mbizup earned 2000 total points
ID: 38410997
If you need additional fields, you will have to use a subquery like this:

SELECT q1.*
FROM qryInitial q1
INNER JOIN 
(SELECT MAX(AuthorizationDate) AS MaxAuthDate, EmployeeID
FROM qryInitial
GROUP BY EmployeeID) q2
ON q1.EmployeeID = q2.EmployeeID AND q1.AuthorizationDate= q2.MaxAuthDate

Open in new window

0
 

Author Closing Comment

by:wlwebb
ID: 38411722
Thank you mbiz.... I really struggle with those subqueries.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

581 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