Fix subquery merge issues