'Lookup a specific instance of a value in a column based on other columns?

I have an event time and employee number and need to match this to corresponding shift start and end times as shown in yellow. Sounds simple manually but there are 690000 events and employees undertake many shifts in this time (some crossing midnight).

main table(left), reference table(right)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source