1

Have following table

PkId   ProfileId    Status   Amount
1         234          0      10
2         235          1      100
3         236          0      50
4         236          1      80
5         237          0      70

For row number 3 and 4 Profile Id is same but I want in resultset it should consider row having value 0 so whereever we have rows where Profile Id is same it should pick row where status =0 And for rest of the rows it should pick as it is.

Expected Result Set:

 PkId   ProfileId    Status   Amount
    1         234          0      10
    2         235          1      100
    3         236          0      50
    5         237          0      70

In expected result set row number 4 has to be omitted because :

  1. 236 Id at 4 is already there row number 3
  2. Value of Status is 1 in row number 4.
Alex
  • 15
  • 5

1 Answers1

0

you could use a join on subselect for min status

select * from my_table m
inner join (
select ProfileId ,   min(Status ) min_status
from my_table 
group by ProfileId
) t on t.profileId = m.profileId and t.min_status = m.status 
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107