Skip to content
Advertisement

Select only the most recent records by record ID

I have an access database, in it, I have a number of records where I need to pull just the latest information .

Here’s the code I am trying to get working :

The idea here, is I need 1 Training, and I need just the employees who took that training, and only the last time they took it.

Currently I am getting a Syntax error in the JOIN statement.

So the two inner Selects:

Work together to get me a list of the last time every training was taken. And the first select

Pulls just the information I need from each of the tables.

Independently these work, except that the first select pulls duplicate trainings (These trainings are done yearly).

I am trying to get rid of that duplication, to produce a yearly report on who has had a specific training.

Sample Tables :

tbl_E

IDNum LastName GivenName Active PersonalInfoColumns EmployeeName
1 Dole Bob -1 stuff Bob Dole
2 Clinton Bill -1 stuff Bill Clinton
3 Bush George HW 0 stuff George HW Bush
4 Reagan Ronald 0 stuff Ronald Reagan
5 Eastwood Clint -1 stuff Clint Eastwood

tbl_C

RecordID Employee Training CompletedDate DSD DSL DR DE
1 1 69 mmddyyyy 0
2 2 74 mmddyyyy
3 3 69 mmddyyyy 1 somewhere 4 somereason
4 4 52 mmddyyyy
5 1 74 mmddyyyy
6 2 69 mmddyyyy 2 somewhere 4 somereason
7 5 69 mmddyyyy 0
972 1 69 mmddyyyy 1 somewhere 4 somereason
973 5 69 mmddyyyy 1 somewhere 2 somereason
974 1 73 mmddyyyy 1 somewhere 2 somereason
974 2 69 mmddyyyy 0

tbl_T (not relevant but it is linked to tbl_C)

ID TrainingName requalifiy
69 Shots yearly
73 Reference Once
74 CORI Once
52 Training yearly

The ideal output of this query is this :

RecordID Employee Training CompletedDate DSD DSL DR DE
3 3 69 mmddyyyy 1 somewhere 4 somereason
972 1 69 mmddyyyy 1 somewhere 4 somereason
973 5 69 mmddyyyy 1 somewhere 2 somereason
974 2 69 mmddyyyy 0

Assuming employee 3 didn’t do it after the first time.

Advertisement

Answer

access is a little bizarre in using SQL as standard, so this SQL that would perfectly work in any SQL backend might not in access. Unfortunately at this moment I don’t have a chance to try:

(If you want, you can join to other such as tbl_E to get names)

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement