Re: [SQL] deciding on one of multiple results returned

2012-12-21 Thread Seth Gordon
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

Re: [SQL] Select every first/last record of a partition?

2012-05-21 Thread Seth Gordon
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 maps...@gmx.net wrote: Hi, suppose a table that has records with some ID and a timestamp. id,    ts 3,    

Re: [SQL] Proper case function

2009-12-31 Thread Seth Gordon
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*