How to perform a query using a specific field of a node entity reference I have a content type that has a node entity reference field. My base query looks like

$event_nids = \Drupal::entityQuery('node')
    -&gt;condition('type', 'my_content_type')
    -&gt;execute();


I'd like though to be able to sort by the title field of the referenced field type. I attempted

$event_nids = \Drupal::entityQuery('node')
    -&gt;condition('type', 'my_content_type')
    -&gt;sort('field_referenced_node.title', ASC)
    -&gt;execute();


But I receive the error 


  Drupal\Core\Entity\Query\QueryException: Invalid specifier 'title' in Drupal\Core\Entity\Query\Sql\Tables->addField()


Is it possible to sort a node query by a field inside a referenced node?
I believe you want something like below. Note that this isn't really a database query at this level but an Entity Query:

$event_nids = \Drupal::entityQuery('node')
  -&gt;condition('type', 'my_content_type')
  -&gt;sort('field_referenced_node.entity.title', ASC)
  -&gt;execute();