Saviynt unveils its cutting-edge Intelligence Suite products to revolutionize Identity Security!
Click HERE to see how Saviynt Intelligence is transforming the industry.
Saviynt Copilot Icon

Query to find the users who have not been assigned roles.

vaibhav05
New Contributor II
New Contributor II

Help me with query that I can use to find the users who have not been assigned roles.

3 REPLIES 3

rushikeshvartak
All-Star
All-Star

SELECT DISTINCT
u.userkey AS userkey,
u.username,
u.displayname AS fullname,
u.email AS email,
u.statuskey
FROM
users u
JOIN
user_accounts ua ON u.userkey = ua.userkey
LEFT JOIN
role_user_account rua ON ua.accountkey = rua.accountkey
WHERE
rua.rolekey IS NULL
AND u.statuskey = '1'
ORDER BY
u.username;


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.

I am getting users who already having roles assigned with this query.

I need query to find users for whome roles are not assigned.

SELECT DISTINCT
u.userkey AS userkey,
u.username,
u.displayname AS fullname,
u.email AS email,
u.statuskey,
r.role_name
FROM
users u
LEFT JOIN
role_user_account rua ON u.userkey = rua.userkey
LEFT JOIN
roles r ON r.rolekey = rua.rolekey
WHERE
rua.userkey IS NULL
AND u.statuskey = '1'
ORDER BY
u.username;


Regards,
Rushikesh Vartak
If this helped you move forward, click 'Kudos'. If it solved your query, select 'Accept As Solution'.