I have a users table and tasks table. Users can have assigned tasks. Each task takes specific range of time. In the tasks table I have a user_id foreign key, date_start (unix timestamp), and date_stop (unix timestamp).
Let's say I want to assign new task which takes place today between 2:30am to 4:00pm to a random user who is free within those hours (doesn't have any task assigned to him which would overlap the new task).
What would be the proper SQL query to retrieve such users?