foo AS f INNER JOIN bar AS b ON f.event_id = b.id WHERE f.id in ( SELECT max(event_id) FROM f WHERE canceled_at IS NULL GROP BY event_id, sheet_id ); REPLACE 構文はMySQLの独自構文
foo AS f INNER JOIN bar AS b ON f.event_id = b.id WHERE f.id in ( SELECT max(event_id) FROM f WHERE canceled_at IS NULL GROP BY event_id, sheet_id ); 一般的なサブクエリ