db_select condition with subquery causes PDOexception
Thanks to @Clive's comment, I checked the documentation about the subqueries on https://drupal.org/node/310086 and I noticed the note about:


  Note: Currently it is only possible to use subselect conditions with the IN operator because with the other operators the sub-query is not wrapped in parentheses and so results in a syntax error. See #1267508: Subselects don't work in DBTNG conditions, except when used as value for IN.


I've changed my code to use IN instead of &gt; and it worked like a charm. Here's the working code for future reference if someone falls into the same situation:

$subquery = db_select('user_revision', 'ur')
  -&gt;fields('ur', array('vid'))
  -&gt;where('ur.timestamp &gt; 1379494886')
  -&gt;orderBy('ur.timestamp', 'ASC');

$query = db_select('users', 'u')
  -&gt;fields('u', array('uid', 'vid'))
  -&gt;condition('u.vid', $subquery, 'IN');

$result = $query-&gt;execute()-&gt;fetchAll();