how do you select columns that match the conditions?

Use distinct on:

select distinct on (customer_id) t.*
from t
order by customer_id, max desc;

distinct on is a Postgres extension that returns on row per whatever is in the parentheses. This row is based on the order by — the first one that appears in the sorted set.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top