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 2012 Forums
 Transact-SQL (2012)
 Delete Rows Query

Author  Topic 

oracle765
Starting Member

13 Posts

Posted - 2013-03-05 : 16:51:46
hi guys I am trying to do a delete to remove duplicate rows but all i want to do is concentrate on the first 3 columns

so if the data in the first 3 columns only match, remove any duplicates, I am not bothered about the rest of the columns in the row being different

Adobe Inc,Version 1.3.1,Licensable,bla,bla,bla,bla
Adobe Inc,Version 1.3.1,Licensable,bla,bla,bla,different bla
Sun Microsystems, Version 11.3.1,bla,bla,bla,bla
Sun Microsystems, Version 11.3.1,bla,bla,bla,bla
Sun Microsystems, Version 11.3.1,bla,bla,bla,different bla
Sun Microsystems, Version 11.4.1,bla,bla,bla,bla

so it should show

Adobe Inc,Version 1.3.1,Licensable,bla,bla,bla,bla
Sun Microsystems, Version 11.3.1,bla,bla,bla,bla
Sun Microsystems, Version 11.4.1,bla,bla,bla,bla



A Lynch

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-05 : 23:38:38
[code];WITH cte AS
(
SELECT ROW_NUMBER() OVER (PARTITION BY col1, col2, col3 ORDER BY (SELECT 1)) AS RN
FROM Tbl
)
DELETE FROM cte WHERE RN > 1;[/code]
Go to Top of Page

oracle765
Starting Member

13 Posts

Posted - 2013-03-06 : 00:48:57
fantastic thats worked

thanks james

A Lynch
Go to Top of Page
   

- Advertisement -