I’ve got three tables: Users, Roles, Authorites
Users
|username|lastName|firstName|....
|dan |foo |dan
|russ |bar |russ
Roles
|role |roleLevel
|ROLE_ADMIN | 0
|ROLE_COMPANY_ADMIN | 20
|ROLE_MARKETING_ADMIN | 50
|ROLE_SERVICE_ADMIN | 80
|ROLE_USER | 100
Authorities
|username|authority
|dan |ROLE_SERVICE_ADMIN |
|dan |ROLE_USER |
|russ |ROLE_MARKETING_ADMIN|
|russ |ROLE_ADMIN |
|russ |ROLE_COMPANY_ADMIN |
I need to get all the DISTINCT users that have a roleLevel higher than the INT I pass in AND their lowest roleLevel
What I have now is:
SELECT DISTINCT u.username, u.firstName, u.lastName, r.roleLevel FROM AUTHORITIES a, ROLES r, USERS u
WHERE r.role = a.authority
AND a.username = u.username
AND r.roleLevel >= #{roleLevel}
ORDER BY u.lastName, u.firstName
but that gives me multiple rows for users with multiple roles. How can I get the users with a lower roleLevel than what I passed in?
It gives you multiple rows because you haven’t specified that you want the lowest; plus you’ve used a greater than not a lower than.