Try this (SQL DEMO)
--Delete records with X if same user has Y
delete t1
from userRoles t1 join (
select * from userRoles t2 where t2.role_id = 'y') t3
on t1.user_id = t3.user_Id
where t1.role_id = 'x'
--Update all Y records to X
update userRoles set role_id = 'X'
where role_id = 'y'
select * from userRoles
--RESULTS
USER_ID ROLE_ID
A X
A Z
B X
C X
D X