1

I have following table in my SQL database

user_

userId | userName

organization_

org_id | parent_org_id_ | name

role_

roleId | roleName

user_roles

userId | roleId

users_organization

userId |  organizationId

...Now what i want is from org_Id= ? and role_name = ? I want to retrieve the name of the user from user_ table related to that organization with the specific role name.so can anyone please tell me.. how to do it?

4

3 に答える 3

2

Try ::

Select *
from
user_ u
INNER JOIN user_roles ur on (u.userId = ur.userId)
INNER JOIN role_ r on (ur.roleId = r.roleId)

INNER JOIN users_organization uo (u.userId = uo.userId)
INNER JOIN organization_ o on (uo.organizationId= o.orgId)
where uo.org_id =? and  r.role_name=?
于 2013-01-04T09:10:15.807 に答える
1

If I understand correctly (your question lacks the table relationships):

SELECT U.userId
    , U.userName
    FROM user_ U
    INNER JOIN users_organization UO ON UO.userId = U.userId
    INNER JOIN user_roles UR ON UR.userId = U.userId
    WHERE UO.organizationId = organizationId
        AND UR.roleName = roleName;

The parameters are organizationId and roleName.

于 2013-01-04T09:14:42.247 に答える
1

Try it out below suggestion.

SELECT u.userName
FROM user_ u
   , role_ r
   , users_organization uo
   , user_roles ur
WHERE r.roleName = ?
  AND uo.organizationId = ?
  AND ur.userId = u.userId 
  AND ur.roleId = r.roleId 
  AND u.userId = uo.userId 
于 2013-01-04T09:16:22.457 に答える