db_condition : nid = tnid I need to retrieve all nodes whose node ID is equal to their tnid, or whose tnid is equal to 0. I am using the following code. 

$db_or = db_or();
$db_or-&gt;condition('nid','tnid','=');
$db_or-&gt;condition('tnid',0,'=');

$query = db_select('node', 'n')
  -&gt;condition($db_or)
  -&gt;fields('n',array('title','nid','tnid','type','language'))
  -&gt;extend('PagerDefault')-&gt;limit(50)
  -&gt;condition('type','article','=')
  -&gt;orderBy('created', 'DESC');


It does not work. It returns 0 node IDs, which is not the expected result, since the following code returns a different result.

db_query_range("select * from {node} where (nid = tnid or tnid = 0) and type = 'article' order by created DESC",0,1000);


If I remove $db_or-&gt;condition('nid','tnid','='); the first query returns only nodes with tnid equal to 0.

So, why does the first OR condition break my code?
You need a where, condition always uses the value literally:

$db_or = db_or();
$db_or-&gt;where('nid = tnid');
$db_or-&gt;condition('tnid',0,'=');