How to add and condition in Query
By default it is and condition

$nids_result = db_select('node', 'n');
$nids_result-&gt;join('users','u','n.uid = u.uid');
$nids_result-&gt;join('users_roles','ur','u.uid = ur.uid');
$nids_result-&gt;fields('n', array('nid'));
$nids_result-&gt;condition('ur.rid', 7, '&lt;&gt;');
$nids_result-&gt;condition('ur.rid', 6, '&lt;&gt;');

// if you have devel installed check this.
dpq($nids_result);
$nids_result = $nids_result-&gt;execute()-&gt;fetchAll();


debugging the query with dpq will tell yuo the exact query that you can run on phpmyadmin and can see what you are missing.

Updated:

if you need query like

SELECT n.nid AS nid
FROM 
{node} n
INNER JOIN {users} u ON n.uid = u.uid
INNER JOIN {users_roles} ur ON u.uid = ur.uid
WHERE ( (ur.rid &lt;&gt; :db_condition_placeholder_0) OR( (ur.rid &lt;&gt; :db_condition_placeholder_1) AND (ur.rid &lt;&gt; :db_condition_placeholder_2) ))


Code will be :

   $nids_result = db_select('node', 'n');
   $nids_result-&gt;join('users','u','n.uid = u.uid');
   $nids_result-&gt;join('users_roles','ur','u.uid = ur.uid');
   $nids_result-&gt;fields('n', array('nid'));
   $db_or = db_or();
   $db_or-&gt;condition('ur.rid', 7, '&lt;&gt;');
   $db_or-&gt;condition(db_and()-&gt;condition('ur.rid', 7, '&lt;&gt;')-&gt;condition('ur.rid', 6, '&lt;&gt;'));
   $nids_result-&gt;condition($db_or);
   $src = $nids_result-&gt;__toString();
   dpm($src);