[nycphp-talk] [OT] SQL Query
Dan Cech
dcech at phpwerx.net
Mon Feb 4 12:53:09 EST 2008
Ben Sgro wrote:
> I have a table that includes an id (not unique and a version).
>
> A unique row is identified by both the id and version. This is for MSSQL.
>
> I want to select all the id's, but only return the most up to date version.
>
> So, for a table
>
> id | version
> -------------
> 1 | 0
> 1 | 1
> 2 | 0
> 2 | 1
> 2 | 2
>
> The query should return
>
> id | version
> -------------
> 1 | 1
> 2 | 2
>
> Any help much appreciated.
This problem is sometimes referred to as the group-wise maximum. I'm
not sure if they would work in mssql but there are a couple of potential
solutions for mysql outlined here:
http://dev.mysql.com/doc/refman/4.1/en/example-maximum-column-group-row.html
Dan
More information about the talk
mailing list