I have the following query:
select "houses"."id",
"houses"."uuid",
COUNT(1) OVER() as full_count from "houses"
CROSS JOIN LATERAL jsonb_array_elements(houses.types) house_types
inner join "hoods" on "hoods"."id" = "houses"."hood_id" and "hoods"."owner_id" = 2
inner join "groups" on "groups"."hood_id" = "hoods"."id" and "groups"."manager_id" = 54
where house_types->>'type' = 'big'
group by "houses"."id", "houses"."uuid"
order by lower(houses.name) asc
limit 20
Which properly gives me the first 20 houses which has a type 'big' that are in the hood which owner_id is 2 AND which hood has an associated group which manager is 54.
Now, the problem is that sometimes I will have houses which name will be the same, and I want to just keep one of those and removing the rest. So for example:
If my houses table looks like:
id, types, name
1, [{ type: 'rating' }], 'white house'
2, [{ type: 'rating' }], 'white house'
3, [{ type: 'rating' }], 'red house'
I would just get the rows with id 1 and 3.
What is a good way to do that in PostgreSQL assuming that I can have both offsets and limits applied to the query, and I want to remove the duplicates.