How to perform a query using a specific field of a node entity reference
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();