How to sort the query results?
Try this out 

use Drupal\Core\Database\Database;

$connection = Database::getConnection();
  //- Step one get all referenced nids
  $query = $connection-&gt;select('node_field_data', 'nfd')
    -&gt;fields('nfd', ['nid', 'created']);
   $query-&gt;innerJoin('node__field_ils_apps', 'app', 'nfd.nid = app.entity_id');
  $query-&gt;orderBy('created', 'DESC');
  $result = $query-&gt;execute()-&gt;fetchAll(PDO::FETCH_ASSOC);