Nested OR clause with EntityFieldQuery I have a table products structure like this  

product_id   product_name   product_created_date   product_expiry_date  availability  
----------   ------------   -------------------    -------------------  ------------
    1           x             12-NOV-13                14-JUN-14               No
    2           y             13-DEC-13                   null                Yes
    3           z             14-DEC-14                14-DEC-15              Yes
    1           p             12-NOV-13                14-JUN-14              Yes 
    ----        --             -----                     ----               ----      


I need a query like :

select product_id from products where (product_expiry_date&gt;='12-DEC-14' or product_expiry_date is null) and availability='Yes'


how to do this using EntityFieldQuery?
I had to do a query like that once, here is how I achieve this with EFQ:

$matches = array();
yourmodule_mini_query('12-DEC-14', $matches);
yourmodule_mini_query('null', $matches);

function yourmodule_mini_query($value, &amp;$matches) {
  $entityQuery = new EntityFieldQuery();
  $query = $entityQuery-&gt;entityCondition('entity_type', 'product');
  $query-&gt;fieldCondition('product_expiry_date', 'value', $value, '=');
  $query-&gt;fieldCondition('availability', 'value', 'Yes', '=');
  $results = $query-&gt;execute();

  if(count($results)) {
    foreach ($results['product'] as $p) {
      // By using product_id as array key, you deal with the duplicates
      $matches[$p-&gt;product_id] = $p-&gt;product_id;
    }
  }
}


Where $matches contains an array of product_id's that are available and for which product_expiry_date is null OR 12-DEC-14.

Hope it helped.

EDIT: As said in the comments below, the evaluation of the NULL value may require a second distinct query instead of calling twice the same function.