As you can see, there are multiple IDs. I have to take one of each ID, based on the conditions. So, I want to check each condition one by one and add a column based on the result in my output. The logic behind this is

if (for each group of ID's) one row has

condition

= 1 then that's the correct one. If both rows are 1 or both are 2, then we check the following condition.

So, If we take only the records with

ID 1

, we can see the

ID 1 - Number 1

is the correct one we need in our output.

But if we take

ID 2

, we see that both records have the same value, which doesn't give us an answer. In that case, we look at

This can be achieved with a self referential derived table. Essentially, you check whether each row would be independently 'Ok' and then join that dataset to itself to check if a previous row was already deemed 'Ok', in which case mark it as 'Not Ok'. This works because your conditions are always 1 or 2 so when creating the row_number you can order in preference of Condition and which will guarantee that the 'first' row to be 'Ok' will have the preferential row_number ie: You won't get any cases of an 'Ok' row being returned with a higher row_number than a 'Not Ok' row for the same ID: