Skip to content
Advertisement

SQL : select the oldest record for each distinct element

I apologize for the poor worded title, let me illustrate first

Here is the table :

Results :

I have several tasks, each of which can have a different status. For every tasks, I want to extract the row with the earliest green status.

So in this case the result would be :

Here is the closest i’ve got to a solution :

It is not good at all, I have to do a query for every single task, totally unpractical.

Is there a way to use a kind of variable and change the last line by something like :

Or maybe another way altogether to solve that problem ?

I greatly thank you for you time.

Advertisement

Answer

Try this:

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