I have a table named tbl_attendance
with these columns and values:
Attendance_id emp_id time status
1 14100003 2019-09-09 04:00:00 1
2 14100003 2019-09-09 12:00:00 2
3 14100004 2019-09-09 22:00:00 1
4 14100004 2019-09-10 06:00:00 2
5 14100005 2019-09-09 23:00:00 1
6 14100005 2019-09-09 23:11:00 1
7 14100005 2019-09-10 07:00:00 2
8 14100005 2019-09-10 07:04:00 2
Now i want to have a result like this:
5 14100005 2019-09-09 23:00:00 1
7 14100005 2019-09-10 07:00:00 2
from the result, i want this conditions to be satisfied,
there are duplicate values from employee ID 14100005 but i want to get the first with status 1 and 2
i need to require the condition if the date has no status 1 or 2, then the query will return nothing.
i have this query and it returns nothing:
SELECT DISTINCT DATE(t.time) AS time, t.employee_id
FROM tbl_attendance AS t
JOIN tbl_attendance AS t2
ON DATE(t.time) = DATE(t2.time) AND t.employee_id = t2.employee_id
WHERE t.`status` = 1 AND t2.`status` = 2
AND DATE(t.time) BETWEEN "2019-09-09" AND "2019-09-10"
AND t.employee_id = 14100005
ORDER BY t.time