title: How to join the same table twice and assign table aliases in Codeigniter?
body: <p>I'm trying to make a mail system in Codeigniter with the PyroCms.
  In my mail table, I have a &quot;recipent&quot; row and a &quot;sender&quot; row which contains the user id of the sender and recipient. To retrieve usernames from the ids, I'm trying to join the table together, but it simply returns me this error:</p>
  <blockquote>
  <p>Error Number: 1066</p>
  </blockquote>
  <blockquote>
  <p>Not unique table/alias: 'default_users'</p>
  </blockquote>
  <blockquote>
  <pre><code>SELECT `default_mailsystem`.*, `default_users`.`username` AS modtager, `default_users`.`username` as afsender
  FROM (`default_mailsystem`)
  LEFT JOIN `default_users` ON `default_mailsystem`.`recipent` = `default_modtager`.`id`
  LEFT JOIN `default_users` ON `default_mailsystem`.`sender` = `default_afsender`.`id`
  ORDER BY `id` DESC
  </code></pre>
  </blockquote>
  <blockquote>
  <p>Filename: /hsphere/local/home/brightmedia/reuseable.dk/modules/mail/models/mail_m.php</p>
  </blockquote>
  <blockquote>
  <p>Line Number: 13</p>
  </blockquote>
  <p>My code is as follows:</p>
  <pre><code>$this-&gt;db-&gt;select('mailsystem.*, users.username AS modtager, users.username as afsender')
      -&gt;join('users', 'mailsystem.recipent = modtager.id', 'left')
      -&gt;join('users', 'mailsystem.sender = afsender.id', 'left');
  $this-&gt;db-&gt;order_by('id', 'DESC');
  return $this-&gt;db-&gt;get('mailsystem')-&gt;result();
  </code></pre>
  <p>The funny thing is, that if I remove the last &quot;join&quot; operation and leave it to only join the recipient of the mail it all works out well.</p>