Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 sql question

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-05-23 : 08:52:42
Rupert writes "Hi,
I have a SQL question hope you can help me.
I have a table that look like this:

id name version
01 xx 1
01 xx 2
02 yy 1
03 zz 2
03 zz 3

I want to see the ids with the max version only, like this:

id name version
01 xx 2
02 yy 1
03 zz 3

How can I wwrite the SELECT statement to do that? (there are many ids, so I can't use where id='1')


Thanks,
Rupert"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-23 : 08:57:51
Select id, name, max(version) as Version from yourTable
Group by id, name

Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-05-23 : 08:59:02
Select Id,Name,Max(Version)As Version From TableName Group by
ID,Name

If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
Go to Top of Page
   

- Advertisement -