WHERE NOT IN using an Array My issue here is that I would like to execute Query 1, return an array of values from Query 1, and then exclude those values from Query 2.  The reason for this is I will be performing an insert function in between (and want to leave my insert function untouched).

Query 1:

$notquery = db_select('uc_packages', 'p')
           -&gt;fields('p', array('package_id'))
           -&gt;condition('p.order_id', $order_id)
           -&gt;condition('p.sid', NULL)
           -&gt;execute()
           -&gt;fetchAll();

foreach($notquery as $foo) {
  $notarr-&gt;pid = $foo;
}


Insert function:

uc_shipping_package_save($package);
...


Query 2:

$query = db_select('uc_packages', 'p')
             -&gt;fields('p', array('package_id'))
             -&gt;condition('p.order_id', $order_id)
             -&gt;condition('p.sid', NULL)
             -&gt;condition('p.order_id', $notarr, 'NOT IN')
             -&gt;execute();


This returns an error:


  Recoverable fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2139 of /var/www/seven/includes/database/database.inc).


It is understandable. My question is how do I pass my array through that query.
Try for the first query:

$notarr = db_select('uc_packages', 'p')
           -&gt;fields('p', array('package_id'))
           -&gt;condition('p.order_id', $order_id)
           -&gt;condition('p.sid', NULL)
           -&gt;execute()
           -&gt;fetchCol();


That way, you'll get the array of package_id, without needing the additional foreach, and avoid the stdClass string conversion error

Presumably also query 2 should be checking package_id instead