If you only want one value per id, then your query should be “SELECT
DISTINCT ON (id) ...”
If you care about which particular value is returned for each ID, then you
have to sort the results: e.g., if you want the minimum value per id, your
query should be “SELECT DISTINCT ON (id) ... ORDER BY val
I think this would work:
select distinct on (id) id, ts --and whatever other columns you want
from mytab
order by id, timestamp desc;
On Mon, May 21, 2012 at 12:04 PM, Andreas wrote:
> Hi,
>
> suppose a table that has records with some ID and a timestamp.
>
> id, ts
> 3, 2012/01/03
> 5,
Michael Gould wrote:
Gary,
Based on what I read it wouldn't handle cases where the result should be
MacDonald from macdonald.
A function that translates “macdonald” to “MacDonald” would also
translate “mackintosh” (the raincoat) to “MacKintosh”, unless you write
it *really really* cleverly.