title: Mysql join mutiple tables to get distinct main table values with pagination and limit
body: <p>I have 3 tables.</p>
  <ol>
  <li><p>users</p>
   <pre>
    Id | first name | last name | email
    1  | john       | pires     | pires@gmail.com
    2  | peter      | robin     | robin@xyz.com
    3  | quinn      | boss      | boss@xyz.com
   </pre>
  </li>
  <li><p>address</p>
   <pre>
    Id | user_id | street       | city  | country
    11  | 1       | street-john  | xyz   | usa
    12  | 2       | street-peter | mnp   |  Austrlia
    13  | 3       | street-quinn | mnp   |  Austrlia
   </pre>
  </li>
  </ol>
  <p>3.contact points.</p>
  <pre>
  
       Id | address_id | type | value
       101 | 11        | phone | 7687676676
       102 | 11        | email | john@yyy.com
       103 | 11        | land phone | 6676
       104 | 12        | website | peter.com
       105 | 12        | website | robin.com
       106 | 12        | website | peter-robin.com
       107 | 12        | website | peter.au
       108 | 13        | website | boss.com
       109 | 13        | website | quinn.com
  
  </pre>
  <p>user related to one address and address related to multiple contact points.</p>
  <p>I need to fetch users with the related address and their contact points.</p>
  <p>So I joined these 3 tables, which results in multiple rows for each user, depending on the number of contact points.</p>
  <pre>
  
      Id | first name |  last name| city | type | value
      1  | john       | pires     | xyz | phone  | 7676767676
      1  | john       | pires     | xyz |email  | john@yyy.com
      1  | john       | pires     | mnp | land phone | 6676
      2  | peter       | robin    | mnp | website | peter.com
      2  | peter       | robin    | mnp | website | robin.com
      2  | peter       | robin    | mnp | website | peter-robin.com
      2 | peter       | robin    | mnp | website | peter.au
      3  | quinn       | boss     | mnp | website | boss.com
      3  | quinn       | boss     | mnp |  website | quinn.com
  
  </pre>
  <p>Then I loop through the rows to get each user and store the contact points in an array for each user.</p>
  <pre><code>&lt;pre&gt;
  { id: 1, firstname: john, city: xyz, contact: [ { type: phone, value: 7676767676 }, { type: email, value: john@yyy}]}
  { id: 2, firstname: peter, city: mnp, contact: [ { type: land phone, value: ... }, { type: .., value: ..}]}
  { id: 3, firstname: quinn, city: mnp, contact: [ { type: website, value: ... }, { type: ..., value: ....}]}
  &lt;/pre&gt;
  </code></pre>
  <p>The problem is when it's paginated.</p>
  <p>When I set a page limit , say 3 in the join query result. then the query results set rows 4,5,6,7 th row has same company with different contact points.</p>
  <p>Then user on a page duplicated on next page. How to solve this issue?
  That is the first page list john, second page list peter and 3 rd page lists peter and quinn. peter is duplicated in 2 nd and 3rd page.
  and the limit I set is 3 .but I get only one user, because other 2 rows are duplicated users.</p>
  <p>What I tried is, added the main query with where IN, where in has select user id with limit set to 3.</p>