Hi everyone, I'm struggling to achieve a Postgres distinct on/order by query using the Exposed DSL...
I'm looking to execute something like this
select distinct on
(cats.name) cats
from
groups_cats
inner join
cats
on
groups_cats.cat_id = cats.id
where
groups_cats.cat_id = 25
order by
cats.name, groups.created desc
I've managed to come up with this
GroupsCats
.join(Cats, JoinType.INNER) { Cats.id eq GroupsCats.catId }
.select { GroupsCats.catId eq catId }
.orderBy(Cats.created to SortOrder.DESC)
But I can't figure out how to make the result distinct on a particular column (cat name in this case)... the
withDistinct()
method sounded hopeful but doesn't seem to work in the way that I need.
If anyone has any ideas/suggestions I would really appreciate it.