Postgres Distinct On
Recently I fixed a tricky N+1 query and thought I should write it up. The need arises when you have a parent child relationship and you need the first child matching some criteria. Simple enough. The tricky part is when you want to bulk load a single child for several parents to avoid an N+1 query.
https://johnnunemaker.com/postgres-distinct-on/
Post a comment