I have a table containing, for example, this data:
id | value | name   | date
1  | 1     | 'one'  | 2015-01-02
2  | 1     | 'two'  | 2015-02-03
3  | 2     | 'three'| 2014-01-03
4  | 2     | 'four' | 2014-01-02
I want for each distinct value, the name of the row with the latest date. So:
value | name   | date
1     | 'two'  | 2015-02-03
2     | 'three'| 2014-01-03
I currently have this query: SELECT value, MAX(date) FROM table GROUP BY value, which gives me the value and date columns I'm looking for. How do I modify the query to add the name field? Simply adding it to the SELECT clause won't work, as Postgres will (understandably) complain I have to add it to the GROUP BY clause. But doing so will add it to the uniqueness check, and my query will return all 4 rows. All I need is the name of the row where it found the latest date.
 
    