SQL query performance question (multiple sub-queries)
问题 I have this query: SELECT p.id, r.status, r.title FROM page AS p INNER JOIN page_revision as r ON r.pageId = p.id AND ( r.id = (SELECT MAX(r2.id) from page_revision as r2 WHERE r2.pageId = r.pageId AND r2.status = 'active') OR r.id = (SELECT MAX(r2.id) from page_revision as r2 WHERE r2.pageId = r.pageId) ) Which returns each page and the latest active revision for each, unless no active revision is available, in which case it simply returns the latest revision. Is there any way this can be