/*
verify the number of records before doing any joining - 135
*/
SELECT
T.EMPLOYEE_ID,
T.TIME_CODE,
T.END_DTTM,
T.UNIT_ID,
T.NP_TIME_CODE,
T.JUSTIFY
FROM employee_times T
WHERE T.unit_id IN ('512')
AND ( T.END_DTTM = TO_DATE('12-24-12','mm-dd-yy')
OR T.END_DTTM = TO_DATE('12-25-12','mm-dd-yy')
OR T.END_DTTM = TO_DATE('12-31-12','mm-dd-yy')
OR T.END_DTTM = TO_DATE('01-01-13','mm-dd-yy') )
ORDER BY T.End_Dttm;
/*
now run with the join, number of records should be the same - 135
*/
SELECT E.Last_Name
|| ', '
|| E.First_Name AS EMPLOYEE,
T.EMPLOYEE_ID,
T.TIME_CODE,
T.END_DTTM,
T.UNIT_ID,
T.NP_TIME_CODE,
T.JUSTIFY
FROM employee_times T
LEFT JOIN
(SELECT DISTINCT employee_id,
last_name,
first_name
FROM employee_profile
WHERE unit_id = '512'
) E
ON E.Employee_Id = T.Employee_Id
WHERE T.unit_id IN ('512')
AND ( T.END_DTTM = TO_DATE('12-24-12','mm-dd-yy')
OR T.END_DTTM = TO_DATE('12-25-12','mm-dd-yy')
OR T.END_DTTM = TO_DATE('12-31-12','mm-dd-yy')
OR T.END_DTTM = TO_DATE('01-01-13','mm-dd-yy') )
ORDER BY E.Last_Name, E.First_Name, T.End_Dttm;