Skip to content
Advertisement

How to select the latest date for each group by number?

I’ve been stuck on this question for a while, and I was wondering if the community would be able to direct me in the right direction?

I have some tag IDs that needs to be grouped, with exceptions (column: deleted) that need to be retained in the results. After which, for each grouped tag ID, I need to select the one with the latest date. How can I do this? An example below:

I am trying to reach this outcome:

So, firstly if there is a date in the “DELETED” column, I would like the row to be present. Secondly, for each unique tag ID, I would like the row with the latest “DATE” to be present.

Hopefully this question is clear. Would appreciate your feedback and help! A big thanks in advance.

Advertisement

Answer

Your results seem to be something like this:

This takes one row where deleted is null — the most recent row. It also keeps each row where deleted is not null.

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