How do I add an OR expression between two ->addExpression() in Drupal 7 I am trying to return flagged content that is either flagged as a favorite or flagged as visited. I can get them to return but i believe Drupal is doing an and between the 2 addExpression() in the query because it is only showing results if either both are flagged. Not one or the other.Here is my code. This is being used for the Drupal Services module to return some values. Any help would be greatly appreciated.

$query-&gt;leftJoin('flag_content', 'flag', "n.nid = flag.content_id AND flag.uid = $user-&gt;uid");
$query-&gt;addExpression("flag.fid is not null AND flag.fid = 2", "is_flagged");
$query-&gt;addExpression("flag.fid is not null AND flag.fid = 3", "is_visited");
addExpression() is for adding expressions to the query, (i.e. fields that will be selected), you can't use it to add conditions.

You could either use a combination of db_and() and db_or() to build up your conditions, or (and probably easier) just use the where() method instead:

$condition = '(flag.fid is not null AND flag.fid = :fid1) OR (flag.fid is not null AND flag.fid = :fid2)';
$query-&gt;where($condition, array(':fid1' =&gt; 2, ':fid2' =&gt; 3);