I have the following table data:
Qns: How do I retrieve only the rows highlighted in Yellow?
Thoughts: What I did try was to do a SUM(A), SUM(B), SUM(C) columns and group by ID_2 column. After which, filter using a WHERE clause on B=1 OR A=1 to retrieve the records. However, I am getting also getting the first record (A23,C1) too based on the select criteria. This is what I would like to avoid retrieving.
1) The first criteria is always to retrieve B=1 as priority for the same ID_2.
2) The second criteria is to retrieve those with A=1 only taking into account that of the first criteria. Hence, based on ID_2, if there is a valid B=1 records that has already been retrieved, it should not retrieve twice.
In this case, A34 is preferred rather than A23 (For instance, if based on ID_2, A or B both have 1, I would ONLY want the row whereby B=1. In addition, A67,A89 are retrieved too.
Appreciate the help in the generation of this SELECT statement.

id_1 in ('A34', 'A67', 'A89')trivially accomplishes what you want.