Query to filter a table based on a comparison applied to the same table?
In a situation like this one, I recommend having two tables:


History (like what you have).  This is a list (a la audit trail) of everything that has happened (INs and OUTs).
Current -- The latest place where each person is.


History has an ever-growing number of rows, and is probably not relevant for the Question at hand.

Current contains one row per person.  A simple SELECT with a WHERE clause should pick out all the persons that are "IN" (or "OUT").

"separate tables for each building or company" -- No.  This is the third time today I have advised against having multiple identical schemas.

On the other hand, Current and History may have the same columns.  This is an exception to the previous paragraph.

Do not split by department or building.