Added client_last and device_last SQL functions