title: Postgres delete all duplicate records but one by sorting
body: <p>I would like to know, in Postgres, how to delete all duplicate records but one by sorting by a column.</p>
  
  <p>Let's say I have the following table <code>foo</code>:</p>
  
  <pre><code> id                 | name |  region   |          created_at
  --------------------+------+-----------+-------------------------------
                    1 | foo  | sydney    | 2018-05-24 15:40:32.593745+10
                    2 | foo  | melbourne | 2018-05-24 17:28:59.452225+10
                    3 | foo  | sydney    | 2018-05-29 22:17:02.927263+10
                    4 | foo  | sydney    | 2018-06-13 16:44:32.703174+10
                    5 | foo  | sydney    | 2018-06-13 16:45:01.324273+10
                    6 | foo  | sydney    | 2018-06-13 17:04:49.487767+10
                    7 | foo  | sydney    | 2018-06-13 17:05:13.592844+10
  </code></pre>
  
  <p>I would like to delete all duplicates by checking for (name, region) tuple, but keep the one with the greatest <code>created_at</code> column. The result would be:</p>
  
  <pre><code> id                 | name |  region   |          created_at
  --------------------+------+-----------+-------------------------------
                    2 | foo  | melbourne | 2018-05-24 17:28:59.452225+10
                    7 | foo  | sydney    | 2018-06-13 17:05:13.592844+10
  </code></pre>
  
  <p>But I do not know where to begin. Any ideas?</p>