Fix subquery issue in task queue