How to find missing attendance from the database table

I have found the correct answer of my question.

I created a month_days table where i inserted all days of 12 months.

id date
1  2017-04-1
2  2017-04-2
3  2017-04-3
.
.
30 2017-04-30
31  2017-05-1
32  2017-05-2
33  2017-05-3
.
.
34 2017-05-31

This is the query

SELECT *
FROM month_days d
CROSS JOIN employees e
LEFT JOIN attendances l ON d.date = DATE( l.log_date ) AND 
e.emp_code = l.emp_code
WHERE l.emp_code IS NULL
GROUP BY d.date, e.emp_code

Leave a Comment