Fix MySQL error in DB optimization due to derived table having no alias