By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE my_table (
user_id int ,
payment_type varchar(5) );
INSERT INTO my_table VALUES
(1,'UPI'),
(1,'NB'),
(2,'UPI'),
(2,'UPI');
select my.user_id,my.payment_type
from my_table my
inner join ( select user_id
from my_table
group by user_id
having count(distinct payment_type)=1
) as t1 on t1.user_id=my.user_id
group by my.user_id,my.payment_type ;
user_id | payment_type |
---|---|
2 | UPI |