I am trying to build an annual leave program.
I have two tables the first one stores all the staff data and the second one contains the staff who are on annual leave with their start and end date.
I want this program to display staff who are not on annual leave while those on annual leave should be hidden between the start and end date of their annual leave date.
This is what I get:
This is what I want:
This is my first table which stores all the staff:
This is my second table which store staff on annual leave:
This is my code:
SELECT tbl_clients.userId, tbl_clients.userName, tbl_clients.userEmail,
tbl_clients.userPhone, tbl_clients.specialId
FROM tbl_clients
LEFT JOIN tbl_absent
ON tbl_clients.specialId = tbl_absent.specialId
WHERE tbl_absent.startDate = ? AND tbl_absent.endDate > ?
2
Answers
You probably want only C and D in your output since only C and D are on leave, rather than B,C,D? Let me know if that is correct.
Fiddle
SQL query can be modified
The goal of these employees can be described as enslavement or something like that, so it should not be like this.
NOT EXISTS ( SELECT 1 FROM tbl_absent WHERE tbl_clients.specialId = tbl_absent.specialId AND '$varCurDate' BETWEEN tbl_absent.startDate AND tbl_absent.endDate )