title: join 3 tables in mysql codeigniter
body: <p>I have 3 tables in my database :-</p>
  
  <ol>
  <li>tbl_roles(role_id,role_name);</li>
  <li>tbl_users(id,role_id,username,email,password);</li>
  <li>tbl_tickets_replies(id,ticket_id,user_id,role_id,comments)</li>
  </ol>
  
  <p><code>role_id, id, id</code> are primary keys of corresponding tables.
  i need :-</p>
  
  <ol>
  <li>username from tbl_users.</li>
  <li>role_name from tbl_roles.</li>
  <li>comments from tbl_tickets</li>
  </ol>
  
  <p>where <code>ticket_id</code> from <code>tbl_tickets_replies</code> = <code>$ticket_id</code> coming as a parameter.</p>
  
  <p>My Model Function is :-</p>
  
  <pre><code>function fetch_comments($ticket_id){
          $this-&gt;db-&gt;select('tbl_tickets_replies.comments,tbl_users.username,tbl_roles.role_name');
          $this-&gt;db-&gt;where('tbl_tickets_replies.ticket_id',$ticket_id);
          $this-&gt;db-&gt;from('tbl_tickets_replies');
          $this-&gt;db-&gt;join('tbl_users','tbl_users.id = tbl_tickets_replies.user_id');
          $this-&gt;db-&gt;join('tbl_roles','tbl_roles.role_id=tbl_tickets_replies.role_id');
          $comments = $this-&gt;db-&gt;get('tbl_tickets_replies');
          return $comments;
       }
  </code></pre>
  
  <p>this is showing database error i.e., I am doing wrong query.
  I want to ask how can I join three tables to fetch data from 3 different tables</p>
  
  <p>This error is showing :-</p>
  
  <blockquote>
    <p>A Database Error Occurred<br>
    Error Number: 1066</p>
    
    <p>Not unique table/alias: 'tbl_tickets_replies'</p>
    
    <p>SELECT <code>tbl_tickets_replies</code>.<code>comments</code>, <code>tbl_users</code>.<code>username</code>,
    <code>tbl_roles</code>.<code>role_name</code> FROM (<code>tbl_tickets_replies</code>,
    <code>tbl_tickets_replies</code>) JOIN <code>tbl_users</code> ON <code>tbl_users</code>.<code>id</code> =
    <code>tbl_tickets_replies</code>.<code>user_id</code> JOIN <code>tbl_roles</code> ON
    <code>tbl_roles</code>.<code>role_id</code>=<code>tbl_tickets_replies</code>.<code>role_id</code> WHERE
    <code>tbl_tickets_replies</code>.<code>ticket_id</code> = '6'</p>
    
    <p>Filename: C:\wamp\www\local.helpdesk.com\bonfire\codeigniter\database\DB_driver.php</p>
    
    <p>Line Number: 330`</p>
  </blockquote>