Skip to content
Advertisement

How to select a single row for each unique ID

SQL novice here learning on the job, still a greenhorn. I have a problem I don’t know how to overcome. Using IBM Netezza and Aginity Workbench.

My current output will try to return one row per case number based on when a task was created. It will only keep the row with the newest task. This gets me about 85% of the way there. The issue is that sometimes multiple tasks have a create day of the same day.

I would like to incorporate Task Followup Date to only keep the newest row if there are multiple rows with the same Case Number. I posted an example of what my current code outputs and what i would like it to output.

Current code

Current output

Current output

Desired output

Desired output

Advertisement

Answer

You could use ROW_NUMBER here:

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