You can run this script to remove the double entries (use with care!). Please first use the select code on top before actually running the delete.
; -- select double entries.
with x as (
select project_id
,project_vrs_id
,max(subroutine_option_no) as max_subroutine_option_no
from subroutine_option
where subroutine_id = 'tsf_user'
and subroutine_type_option_id = 'SCHEMABINDING'
group by project_id
,project_vrs_id
having count(*) > 1
)
select *
from subroutine_option as so
join x
on so.project_id = x.project_id
and so.project_vrs_id = x.project_vrs_id
-- and so.subroutine_option_no = x.max_subroutine_option_no
where so.subroutine_id = 'tsf_user'
and so.subroutine_type_option_id = 'SCHEMABINDING'
; -- delete double entries
with x as (
select project_id
,project_vrs_id
,max(subroutine_option_no) as max_subroutine_option_no
from subroutine_option
where subroutine_id = 'tsf_user'
and subroutine_type_option_id = 'SCHEMABINDING'
group by project_id
,project_vrs_id
having count(*) > 1
)
delete so
from subroutine_option as so
join x
on so.project_id = x.project_id
and so.project_vrs_id = x.project_vrs_id
and so.subroutine_option_no = x.max_subroutine_option_no
where so.subroutine_id = 'tsf_user'
and so.subroutine_type_option_id = 'SCHEMABINDING'