Fix mysql subquery handling