SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Delete Rows Query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

oracle765
Starting Member

Australia
13 Posts

Posted - 03/05/2013 :  16:51:46  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3649 Posts

Posted - 03/05/2013 :  23:38:38  Show Profile  Reply with Quote
;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;
Go to Top of Page

oracle765
Starting Member

Australia
13 Posts

Posted - 03/06/2013 :  00:48:57  Show Profile  Reply with Quote
fantastic thats worked

thanks james

A Lynch
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000