Select users that do have certain roles and do not have others
According to Drupal db_select API Use this to fetch user id and names that user have roleId 13 and not have roleId 14

$query = db_select('user', 'u');
$query-&gt;join('role', 'ur', 'u.uid = ur.uid'); 
$query-&gt;fields('u',array('uid','name'))
 -&gt;condition('ur.rid', 13)
 -&gt;condition('ur.rid', 14,'&lt;&gt;');
 $result = $query-&gt;execute()-&gt;fetchAll();
dpm($result);