title: Select first or random row in group by
body: <p>I have this query using PostgreSQL 9.1 (9.2 as soon as our hosting platform upgrades):</p>
  
  <pre><code>SELECT
      media_files.album,
      media_files.artist,
      ARRAY_AGG (media_files. ID) AS media_file_ids
  FROM
      media_files
  INNER JOIN playlist_media_files ON media_files.id = playlist_media_files.media_file_id
  WHERE
      playlist_media_files.playlist_id = 1
  GROUP BY
      media_files.album,
      media_files.artist
  ORDER BY
      media_files.album ASC
  </code></pre>
  
  <p>and it's working fine, the goal was to extract album/artist combinations and in the result set have an array of media files ids for that particular combo.</p>
  
  <p>The problem is that I have another column in media files, which is <code>artwork</code>.</p>
  
  <p><code>artwork</code> is unique for each media file (even in the same album) but in the result set I need to return just the first of the set.</p>
  
  <p>So, for an album that has 10 media files, I also have 10 corresponding artworks, but I would like just to return the first (or a random picked one for that collection).</p>
  
  <p>Is that possible to do with only SQL/Window Functions (first_value over..)?</p>