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
 General SQL Server Forums
 New to SQL Server Programming
 basic sql query

Author  Topic 

rahulsh
Starting Member

1 Post

Posted - 2012-02-18 : 04:31:21
Hi All,
I have a table of three columns containing name,version and data
.There can be multiple tuples of same name but with different version. From each group of same names, I want to delete those tuples for which the version is smallest.Ex
NAME VERSION DATA
A 1 nething
A 2 nething
B 3 nething
B 3 nething
B 4 nething
after operation, the tuples left in the table must be
A 2 nething
B 4 nething
Please help me out in this query.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-02-18 : 06:26:22
SELECT NAME, MAX(VERSION) Ver, DATA
INTO #a
FROM myTable
GROUP BY NAME, DATA

TRUNCATE TABLE myTable

INSERT myTable(NAME, VERSION, DATA) SELECT NAME, Ver, DATA FROM #a
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-18 : 15:33:56
will data be same value always?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -