all groups > sql server new users > september 2006 >
You're in the

sql server new users

group:

how to query


how to query Anders Eriksson
9/21/2006 12:00:00 AM
sql server new users: Hello,

If I have this table:

IdNo int
Version int
data ...

IdNo and Version is the primary key.

How would I write an SQL query to get the latest version of a all IdNo?

// Anders
--
English is not my first, or second, language
so anything strange, or insulting, is due to
the translation.
Re: how to query Jens
9/21/2006 7:33:56 AM
Select * From SomeTable ST
INNER JOIN
(
Select IDCol,MAX(Version) FROM SomeTable
Group by IDCol
) ST2
ON ST.IDCol = ST2.IDCol
AND ST.Version = ST2.Version

SUbstitute the * by the needed columns.

HTH, Jens K. Suessmeyer

---
http://www.sqlserver2005.de
---
AddThis Social Bookmark Button