Hm your SELECT (and therefore your result set) is missing path.strPath now which is used further down in a condition. Any reason why the additional conditions on files and path are only needed for locked users? Do they hurt (besides the fact that the query will be a bit slower) in the other cases?