November 11, 2012 at 5:04 pm
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
November 12, 2012 at 5:16 am
http://stackoverflow.com/questions/18932/how-can-i-remove-duplicate-rows
Using Google for a bit probably won't kill you.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
November 16, 2012 at 1:46 pm
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
----------------------------------------------------
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply