I need to select a table that have one join table
for example there are tables:
Role,AccountRole,Account
AccountRole - many to many relationship
need to select role, which has one account
Role table
id name
1 admin
2 user
3 external
Account table
id name
1 homer
2 jessica
3 simpson
AccountRole table
account_id role_id
1 1
1 2
2 2
3 3
query:
SELECT role.id
FROM Role role
INNER JOIN AccountRole accRole
ON accRole.role_id = role.id
INNER JOIN Account acc
ON accRole.account_id = acc.id
GROUP BY role.id
HAVING COUNT(*) = 1
in the query result:
role.id
2
3
but I need role.id which role.name = “external”(in this instance role.id = 3,but not 2)
how to do this
1 Answer