Using EntityFieldQuery to order nodes in an OG Group using node_comment_statistics table I have an EntityFieldQuery to fetch nodes of a certain type which belong to an OG group in a Drupal Commons instance.

  $query = new EntityFieldQuery();
  $query-&gt;entityCondition('entity_type', 'node')
    -&gt;entityCondition('bundle', array('post', 'document', 'link'), 'IN')
    -&gt;propertyCondition('status', 1)
    -&gt;fieldCondition('og_group_ref', 'target_id', $panel_args[0], '=');


I was wondering if it was possible to also add the condition to order the nodes by most recent comment using the information from the node_comments_statistics table and the last_comment_timestamp.

Is this possible with EFQ since their are no joins? Or will I have to fall back to a basic Drupal Query?
Add the custom TAG to the EntityFieldQuery and than use the hook_query_TAG_alter() to add the JOIN to the query as below:
// Create the query as below (Note: &quot;CUSTOMTAG&quot; added for altering the query)
$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'node')
  -&gt;entityCondition('bundle', array('post', 'document', 'link'), 'IN')
  -&gt;propertyCondition('status', 1)
  -&gt;fieldCondition('og_group_ref', 'target_id', $panel_args[0], '=');
  // Added the Tag, which we will be using to alter the query.
  -&gt;addTag('CUSTOMTAG');
  // Complete the query (if you are having any other field condition).
  -&gt;execute();
  
/**
 * Implements hook_query_TAG_alter()
 */
function MyModule_query_CUSTOMTAG_alter(QueryAlterableInterface $query) {
  // Add the join to the &quot;node_comment_statistics&quot; table.
  $query-&gt;join('node_comment_statistics', 'ncs', 'ncs.nid = node.nid');
  $query-&gt;orderBy('ncs.last_comment_timestamp')
}

Reference links:
https://drupal.org/node/1157006#comment-7634027
http://www.phase2technology.com/blog/or-queries-with-entityfieldquery/