title: SQL SELECT statement with users, roles and rights
body: <p>Lets say that I have tables:</p>
  
  <ol>
  <li>Users</li>
  <li>Users_in_Roles</li>
  <li>Roles</li>
  <li>Rights_in_Roles</li>
  <li>Rights</li>
  </ol>
  
  <p>Keys are standard( UserFk, RoleFk, RightFk)</p>
  
  <p>The question is: how to get all users that are in role with right X (id = 100)</p>
  
  <p>I Have no idea how to touch this problem. Please help and sorry for my english.</p>
  
  <pre><code>SELECT [dbo].[System_Users].[Id]
    ,[UserName]
    ,[FirstName]
    ,[LastName]
    ,[Email]
    ,RoleFk
    ,[dbo].[System_Roles].Name
    FROM [dbo].[System_Users]
  INNER JOIN [dbo].[System_Roles_System_Users]
  ON [dbo].[System_Roles_System_Users].UserFk = [dbo].[System_Users].Id
  INNER JOIN [dbo].[System_Roles]
  ON [dbo].[System_Roles].Id = [dbo].[System_Roles_System_Users].RoleFk
  
  WHERE ?
  </code></pre>
  
  <hr>
  
  <p>I tryied sth like that, could you tell me what iw wrong? </p>
  
  <pre><code>SELECT 
  DISTINCT System_Users.Id,
  System_Users.FullName
  FROM System_Users
  INNER JOIN Dict_Rights_System_Users
  ON System_Users.Id = Dict_Rights_System_Users.UserFk
  INNER JOIN System_Roles_System_Users
  ON System_Roles_System_Users.UserFk = System_Users.Id
  WHERE
  RightFk = 136
  OR
  136 IN (SELECT Dict_Rights_System_Roles.RightFk FROM Dict_Rights_System_Roles WHERE             
  Dict_Rights_System_Roles.RoleFk = System_Roles_System_Users.RoleFk)
  ORDER BY System_Users.FullName ASC
  </code></pre>