LPS-33388 Refactor max row in group subquery to self left join with null filtering to get rid of derived table usage