with t as (select user_id, role_id from user_role valid_date > sysdate)select a.* from t a, (select user_id from t group by user_id having count(*) = 1) b, (select role_id from t group by role_id having count(*) = 1) c where a.user_id = b.user_id and a.role_id = c.role_id