Good day,
I have three tables in our payroll system that I need to select against. I either get duplicates of all employee records for that operator or only those that have no duplicate records at all.
I want to select only the most recent record for all employees who work in a department which is supervised by operator id 10001. Jane has three total records and two records against her name for the same date so the sequence indicates the most current.
The result set would be:
Returns duplicate records but none of Jane's (E2).
TIA
I have three tables in our payroll system that I need to select against. I either get duplicates of all employee records for that operator or only those that have no duplicate records at all.
Code:
Table1: Operators to department (A)
oprid deptid
10001 DEPT1
10001 DEPT2
10002 DEPT2
10002 DEPT3
Table2: Department to employee "B"
deptid Emplid
DEPT1 E1
DEPT2 E2
DEPT2 E3
DEPT2 E4
DEPT3 E5
Table3: Employee To Employee Name "C"
emplid Name effdt effseq
E1 John Smith 2001-01-01 1
E2 Jane Doe 2000-01-05 1
E2 Jane Smith 2007-09-15 1
E2 Jane Doe-Smith 2007-09-15 2
E3 Dudley Doright 2007-01-11 1
E4 Mary Contrary 2000-05-12 1
E5 Kevin Nivek 1999-02-22 1
The result set would be:
Code:
Emplid Name Effdt effseq
E2 Jane Doe-Smith 2007-09-15 2
E3 Dudley Doright 2007-01-11 1
E4 Mary Contrary 2000-05-12 1
[\code]
My attempt (among many others)
[code]
select B.emplid, B.effdt, B.effseq, A.deptid, C.name
from A, B, C
where A.oprid="10001"
and B.deptid=A.deptid
and B.effdt =
(select max(SS.effdt) from B SS
where SS.emplid = B.emplid
and SS.empl_rcd=0
Group by B.emplid
)
and B.effseq =
(select max(SS.effseq) from B SS
where SS.emplid = B.emplid
and SS.empl_rcd=0
Group by B.emplid
)
and C.emplid=B.emplid;
TIA