Rewriting a slow SQL (sub) query in JOIN
问题 So I've got massive slow SQL query and I've narrowed it down to a slow sub-query, so I want to rewrite it to a JOIN. But I'm stuck... (due to the MAX and GROUP BY ) SELECT * FROM local.advice AS aa LEFT JOIN webdb.account AS oa ON oa.shortname = aa.shortname WHERE aa.aa_id = ANY (SELECT MAX(dup.aa_id) FROM local.advice AS dup GROUP BY dup.shortname) AND oa.cat LIKE '111' ORDER BY aa.ram, aa.cpu DESC LIMIT 0, 30 回答1: Here is a different version of your query where the subquery is converted