title: Merge Subquery results column into a single column then use in ORDER BY
body: <p>I would like to execute some query like this:</p>
  
  <pre><code>SELECT 
      folders.*, 
      (SELECT 
          files.filename 
       FROM 
          files 
       WHERE 
          files.folder_id = folders.id 
      ) 
      as files 
  FROM 
          folders 
  ORDER BY 
      files[column name of filename]
  </code></pre>
  
  <p>The sub-query may give more than 1 result, so I would like to join the results into a single column filename.</p>
  
  <p>I am using Postgres.
  I added Rails as a tag because you might suggest some Rails magic that can handle this.</p>