Q&A for people looking to bypass life's everyday problems with simple tricks
with ParentIDRank AS (select id, parentid, row_number() OVER (partition by parentid order by id desc) AS ParentIDRowNumber from posts where parentid is not null) Select * from ParentIDRank where ParentIDRowNumber = 1 order by parentid asc, parentidrownumber asc