Excluding specific user role from query
Try

$query = 'SELECT DISTINCT(ur.uid) 
  FROM {users_roles} AS ur
  WHERE ur.rid IN (:rids) AND ur.rid NOT IN (:rids2)';

$result = db_query($query, array(':rids' =&gt; array(7), ':rids2' =&gt; array(8)));


Or if you wanted just the more specific version

$query = 'SELECT DISTINCT(ur.uid) 
  FROM {users_roles} AS ur
  WHERE ur.rid = (:rids) AND ur.rid != (:rids2)';

$result = db_query($query, array(':rids' =&gt; 7, ':rids2' =&gt; 8));