How to use NOT EXISTS condition?
Why not use a simple db_query()? In many cases, this is a perfectly adequate way of doing things; you can still use named parameters, and you can build your query as you'd like. It actually performs (very) slightly better than a db_select() anyways (see: http://drupal.org/node/1067802 and https://drupal.stackexchange.com/a/1205/26).

The only reason to not use a db_query() for a particular select query is if you need the query to be easily extended or changed by some other module.

$result = db_query('SELECT uid
  FROM users
  WHERE NOT EXISTS(SELECT NULL
    FROM users_roles
    WHERE users_roles.uid = users.uid
  )')-&gt;fetchCol();


Anyways, your particular query is a little more complex than normal, but can still be done using D7's DB API. See:


http://drupal.org/node/1001242#comment-3921430
Database query with notExists ($query-&gt;condition('', $subquery, 'EXISTS');)