slow in subquery in mysql, so do the subquery first