SELECT CAST(spawner.vehicle_entity_id AS TEXT) AS vehicleId, CAST(spawner.vehicle_entity_id AS TEXT) AS entityId, entity.class AS className, spawner.vehicle_alias AS label, entity.location_x AS x, entity.location_y AS y, entity.location_z AS z, strftime('%Y-%m-%dT%H:%M:%SZ', spawner.vehicle_last_access_time, 'unixepoch') AS lastAccessTime, spawner.is_vehicle_functional AS isFunctional, 1 AS existsInGame, group_concat(DISTINCT CAST(mount.prisoner_id AS TEXT)) AS mountedPrisonerIds, group_concat(DISTINCT CAST(mounted_profile.id AS TEXT)) AS mountedUserProfileIds, group_concat(DISTINCT mounted_profile.user_id) AS mountedSteamIds FROM vehicle_spawner spawner JOIN entity ON entity.id = spawner.vehicle_entity_id LEFT JOIN prisoner_vehicle_mountee_info mount ON mount.vehicle_entity_id = spawner.vehicle_entity_id LEFT JOIN prisoner mounted_prisoner ON mounted_prisoner.id = mount.prisoner_id LEFT JOIN user_profile mounted_profile ON mounted_profile.prisoner_id = mounted_prisoner.id WHERE (:vehicleId IS NULL OR CAST(spawner.vehicle_entity_id AS TEXT) = :vehicleId) AND (:search IS NULL OR spawner.vehicle_alias LIKE '%' || :search || '%' OR entity.class LIKE '%' || :search || '%') AND (:activeWithinSeconds IS NULL OR spawner.vehicle_last_access_time >= CAST(strftime('%s', 'now') AS INTEGER) - :activeWithinSeconds) GROUP BY spawner.vehicle_entity_id ORDER BY spawner.vehicle_last_access_time DESC LIMIT COALESCE(:limit, 500)