I am storing employee attendance on a table ‘attendance’ having the following structure:
EmpID, CDate
Attendance system insert this table everyday with employee-id of all employees present on that particular day.
I need to find out absent statement of a particular employee. I can do this easily by selecting all distinct date that are not in – dates where the employee is present.
Is there any way I can remove the not in operator on that sql statement. Please help
Here is the sql query for employee with EmpId 01:
select distinct CDate
from attendance
where CDate not in (
Select CDate from attendance where EmpID='01')
The problem isn’t in the NOT IN clause, it is the subquery.
You want something more like:
This is a cartesian join which pulls all of the dates, then joins the employee attendance status on that. Should be significantly faster than your subquery.
Updated, with tested code:
My bad on the previous answer. I should have put the subselection into the ON instead of an aggregate.