I have a query like this:
select * from wallet w
join where_to_pay wtp on wtp.wallet_id = w.id
join (select wallet_id w_id, max(business_id) from where_to_pay group by wallet_id) on w_id = w.id
As you can see, there is two joins between wallet and where_to_pay tables. The only different is, in the second join, the rows are grouped by wallet_id (which returns an unique business_id).
Since those two joins are similar, I want to know, is it possible to remove one of them and use a window function (such as row_number or first_row or what's needed) instead?