Getting error while joining two tables Here is query which is, I am using 

$query = db_select('users','u');
$query-&gt;join('users_roles', 'u.uid = users_roles.uid'); // JOIN users_roles with users
$query-&gt;fields('users', array('name','uid')) // SELECT the field name from users
    -&gt;condition('users_roles.rid', 5);   

  $results = $query-&gt;execute();


Actually i want the user name and id for that those user who are under role id = 5


  PDOException: SQLSTATE[42000]: Syntax error or access violation: 1066
  Not unique table/alias: 'u': SELECT users.name AS name, users.uid AS
  uid FROM {users} u INNER JOIN {users_roles} u.uidusers_roles.uid WHERE
  (users_roles.rid = :db_condition_placeholder_0) ; Array (
  [:db_condition_placeholder_0] => 5 ) in user_assign_list() (line 80 of
  C:\xampp\htdocs\nic\sites\all\modules\user_assign\user_assign.module).


This error shown on the browser. Actually i am creating the custom module file for this requirement. Is there any need to include sql connection for those custom module?
here is .module file

&lt;?php
function user_assign_permission() {
  return array(
    'submit user_assign' =&gt; array(
      'title' =&gt; t('Submit user_assign'),
      'description' =&gt; t('Submit the user_assign form'),
    ),
    'access user_assign list' =&gt; array(
      'title' =&gt; t('Access user_assign list'),
      'description' =&gt; t('Access the user_assign submissions'),
    ),

  );
}
function user_assign_menu() {
  $items = array();

   $items['users-list'] = array(
    'title' =&gt; t('User Assign'),
    'page callback' =&gt; 'user_assign_list',
    'access callback' =&gt; TRUE,
    'access arguments' =&gt; array('access user_assign list'),
    'type' =&gt; MENU_CALLBACK,
  );
  return $items;
}


function user_assign_theme($existing, $type, $theme, $path) {
  return array(
    'user_assign_function' =&gt; array(
      'variables' =&gt; array('rows' =&gt; NULL),
    ),
    'user_assign_template' =&gt; array(
      'variables' =&gt; array('rows' =&gt; NULL),
      'template' =&gt; 'user_assign_template',
    ),


  );
}



function theme_user_assign_function($variables)
{
    $output = '';

//   print_r($variables);
    foreach($variables['items'] as $row) {

     $output .= '&lt;div class="views-row"&gt;&lt;div class="do_featured"&gt;
   &lt;div class="do_title"&gt;
    &lt;span&gt;    &lt;div class="field"&gt;&lt;div class="field-items"&gt;'.$row[1].'&amp;nbsp'.$row[2].'&lt;/div&gt;&lt;/div&gt;
    &lt;/span&gt; 
   &lt;/div&gt;&lt;/div&gt;';



    }

    return $output;
}

function user_assign_list() {
 // $query = db_select('users', 'n');

//  $query-&gt;condition('n.empname', '%' . db_like($_GET['empname']). '%','LIKE');

 // $query-&gt;fields('n', array('fe_id', 'empcode','empname','empphoto','empemail','empdesignation'))
  //    -&gt;limit(4)
  //    -&gt;addTag('node_access')
  //    -&gt;groupBy('n.fe_id');
$query = db_select('users','u');
$query-&gt;join('users_roles', 'u.uid = users_roles.uid'); // JOIN users_roles with users
$query-&gt;fields('users', array('name','uid')) // SELLECT the field name from users
    -&gt;condition('users_roles.rid', 5);


  $results = $query-&gt;execute();
     $rows = array();
  foreach($results as $result)
  {
    $rows[] = array(
        $result-&gt;uid,
        $result-&gt;name,
        );

  }
  $output = theme('user_assign_function', array('items' =&gt; $rows));
  return $output;
}

?&gt;
Hi Sumit check the below query and it not showing any error. 

Use Query coder module to create any query in drupal format

Query coder Convert SQL query to Drupal Database abstraction layer code.

$query = db_select('users','u');

$query->join('users_roles', 'r', 'u.uid = r.uid'); // JOIN users_roles with users

$query->fields('u', array('name','uid')) // SELECT the field name from users
    ->condition('r.rid', 5);

$results = $query->execute();
     $rows = array();

foreach($results as $result)
  {

$rows[] = array(
    $result-&gt;uid,
    $result-&gt;name,
    );


}