Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

duplicate rows Expand / Collapse
Author
Message
Posted Sunday, November 11, 2012 5:04 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 21, 2013 12:01 PM
Points: 149, Visits: 346
hi

my table has following data

productno productname des quantity

1 borin 4x-mal 2
1 borin 5x-cal 3
2 hypoid 4-5cal 4
2 hypoid 4-5cal 4

here,i want to delete rows which has productno and productname same,it doesnt matter des and quantity is same or not.

i just want 1 row ,with combination of productno and productname
Post #1383483
Posted Monday, November 12, 2012 5:16 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 1:01 PM
Points: 9,366, Visits: 6,463
http://stackoverflow.com/questions/18932/how-can-i-remove-duplicate-rows

Using Google for a bit probably won't kill you.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1383624
Posted Friday, November 16, 2012 1:46 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 4:43 PM
Points: 192, Visits: 640
If I understood correctly >

create table #t1 (productNo tinyint, productname varchar(10),
Des varchar(50), quantity tinyint)

Insert into #t1
select 1, 'borin', '4x-mal', 2 union all
select 1, 'borin', '5x-cal', 3 union all
select 2, 'hypoid', '4-5cal', 4 union all
select 2, 'hypoid', '4-5cal', 4
---

;with cte as (
select row_Number() over (partition by productNo, ProductName
order by quantity desc /* arbitrary */) AS COLUMN1,
*
FROM #T1)
DELETE FROM CTE WHERE COLUMN1>1

select * from #t1
drop table #t1

Post #1385856
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse