I am trying to select rows in an SQL table based on multiple conditions within the same unique ID.
I have the following table:
ID Status
1 AS
2 Rec
2 AS
The rules are as follows:
If an [ID] has both 'Rec' and 'AS', select only the row with 'Rec'. In other words, 'Rec' has precedence over 'AS'.
If the [ID] does not have 'Rec', select the row with 'AS'.
I want the query to output only the rows ID=1,Status=AS
and ID=2,Status=Rec
.
What is the query to select only these two rows?