How do I add a condition to a query? $acl_ids = array(1,2,3);
$database = \Drupal::database();

$result = $database
  -&gt;query("SELECT {nid} FROM {acl_node} WHERE grant_update = :grant", 
    ['grant' =&gt; 1,])
  -&gt;condition('acl_id', $acl_ids, 'in')
  -&gt;fetchField();


Unfortunately the -&gt;condition part does not work, since I get the following error:


  Call to undefined method Drupal\Core\Database\Statement::condition()


What method should I instead use?
Conditions are only used in dynamic queries; the query() method is for running static SQL.

The dynamic version would be something like:

$result = $database
  -&gt;select('acl_node', 'n')
  -&gt;fields('n', ['nid'])
  -&gt;condition('grant_update', 1)
  -&gt;condition('acl_id', $acl_ids, 'IN')
  -&gt;execute()
  -&gt;fetchField();


And the static:

$result = $database
  -&gt;query("SELECT nid FROM {acl_node} WHERE grant_update = :grant AND acl_id IN (:acl_ids[])", [':grant' =&gt; 1, ':acl_ids[]' =&gt; $acl_ids])
  -&gt;fetchField();