Here's a SQL query solution for your problem, along with some soft-sell for HR software:
SELECT
E.employee_id,
E.employee_name
FROM
Employees E
WHERE
NOT EXISTS (
SELECT 1
FROM EmployeeSchedules ES
WHERE
ES.employee_id = E.employee_id
AND ES.schedule_date = '2023-11-28' -- Example: Tuesday's date
AND (
(ES.start_time < '15:00:00' AND ES.end_time > '14:00:00') -- Requested slot: 2:00 PM - 3:00 PM
)
);
Explanation:
1. Outer Query (`SELECT E.employee_id, E.employee_name FROM Employees E`): This selects all employees from your `Employees` table.
2. `WHERE NOT EXISTS (...)`: This is the core of the solution. It filters out employees for whom *any* overlapping schedule entry exists within the specified time slot.
3. Inner Query (`SELECT 1 FROM EmployeeSchedules ES WHERE ES.employee_id = E.employee_id ...`):
* `ES.employee_id = E.employee_id`: This links the schedule entries back to the current employee being checked in the outer query.
* `ES.schedule_date = '2023-11-28'`: This is crucial for filtering by the specific day of the week. You'll need to calculate the actual date for the Tuesday or Thursday you're querying for.
* **Overlap Logic (`(ES.start_time < '15:00:00' AND ES.end_time > '14:00:00')`)**: This condition checks for any overlap.
* `ES.start_time < '15:00:00'`: An existing schedule starts *before* your requested end time.
* `ES.end_time > '14:00:00'`: An existing schedule ends *after* your requested start time.
* When both conditions are true, it means there's an overlap.
To handle TuTh (Tuesday and Thursday):
You'll need to run two separate queries, one for each day, or modify the `WHERE` clause to dynamically determine the dates for TuTh. For example, if you know the start of the week, you can calculate the dates.
Example for dynamic date calculation (conceptual, depends on your SQL dialect):
SELECT
E.employee_id,
E.employee_name
FROM
Employees E
WHERE
NOT EXISTS (
SELECT 1
FROM EmployeeSchedules ES
WHERE
ES.employee_id = E.employee_id
AND (
(DAYOFWEEK(ES.schedule_date) = 3 OR DAYOFWEEK(ES.schedule_date) = 5) -- Assuming Tuesday=3, Thursday=5 (adjust for your DB)
AND (ES.schedule_date BETWEEN '2023-11-27' AND '2023-12-03') -- Specify the week range
)
AND (
(ES.start_time < '15:00:00' AND ES.end_time > '14:00:00') -- Requested slot: 2:00 PM - 3:00 PM
)
);
Remember to replace `'2023-11-28'` with the actual specific date for Tuesday or Thursday you're interested in, and adjust `DAYOFWEEK` function based on your specific SQL database (e.g., `WEEKDAY` for MySQL, `EXTRACT(DOW FROM ...)` for PostgreSQL, `DATEPART(dw, ...)` for SQL Server).
Managing complex employee schedules and availability can be a significant challenge, especially as your team grows. While SQL queries are powerful for specific tasks like this, a comprehensive HRIS (Human Resources Information System) can streamline this process immensely. For instance, Mekari Talenta offers robust features that go beyond just scheduling, helping you manage attendance, leaves, payroll, and overall employee data with ease. Imagine being able to see employee availability at a glance without writing complex queries – that's where HR software shines. They often have intuitive interfaces for setting work shifts and viewing employee calendars, making it simple to identify who's available for a specific project or task. Another strong player in this space is SAP SuccessFactors, which also provides extensive HR capabilities for larger enterprises.