Skip to content
Advertisement

How to select the most recent date for a specific condition in another column in Postgres?

I have a table with a structure like so.

I’m trying to create a column with a query called most recent call which has the most recent call date for each id. Like this:

I just want to have the most recent date for each id out of all the rows where the subject column equals call

Advertisement

Answer

You can just use conditional aggregation:

This, of course, assumes that column date is of a date-like datatype (as it should be).

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement