emerickson
Technical User
Hello,
I have a table with all kinds of absence records for all employees, but I only want to get the last absence for each employee. Here is what I tried:
SELECT DISTINCT SocSec, BeginAbsenceDate, AbsenceCode,
(SELECT TOP 1 BeginAbsenceDate
FROM tblAttendance
WHERE socsec = tblAttendance.SocSec
ORDER BY BeginAbsenceDate DESC) FROM tblAttendance
ORDER BY SocSec
Instead of giving me the latest record of each employee, it gives me all records with the date of the last record attached to each employee's record.
If it can't be solved with SQL, is there a way I can just have a plain SQL select statement, but then use some ColdFusion to retrieve the last record for each employee from the query?
Thanks,
Eva Erickson
I have a table with all kinds of absence records for all employees, but I only want to get the last absence for each employee. Here is what I tried:
SELECT DISTINCT SocSec, BeginAbsenceDate, AbsenceCode,
(SELECT TOP 1 BeginAbsenceDate
FROM tblAttendance
WHERE socsec = tblAttendance.SocSec
ORDER BY BeginAbsenceDate DESC) FROM tblAttendance
ORDER BY SocSec
Instead of giving me the latest record of each employee, it gives me all records with the date of the last record attached to each employee's record.
If it can't be solved with SQL, is there a way I can just have a plain SQL select statement, but then use some ColdFusion to retrieve the last record for each employee from the query?
Thanks,
Eva Erickson