maxbe fixed database query