title: How create SQL pagination difficult join query with duplicate data?
body: <p>I have several tables in the database.
  Users, profiles and user roles.
  The relationship of profiles and users one to one.
  The relationship of roles and users many to many.</p>
  
  <p><a href="https://i.stack.imgur.com/Tp5mu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tp5mu.png" alt="Scheme"></a></p>
  
  <p>To select all users, I send the following request:</p>
  
  <pre><code>SELECT A.role_id, A.role_name, A.user_id,B.user_username, B.user_password, B.profile_color_text, B.profile_color_menu, B.profile_color_bg FROM
    (SELECT Roles.role_id, Roles.role_name, UserRoles.user_id 
        FROM Roles INNER JOIN UserRoles ON Roles.role_id = UserRoles.role_id) AS A 
  LEFT JOIN 
    (SELECT Users.user_username, Users.user_password, Profiles.profile_color_text, Profiles.profile_color_menu, Profiles.profile_color_bg, Profiles.profile_id 
        FROM Users INNER JOIN Profiles ON Users.user_id = Profiles.profile_id) AS B
  ON A.user_id = B.profile_id;
  </code></pre>
  
  <p><strong>The question is how do I select a pagination?</strong></p>