if 3 duplicate records in a table,i want to delete 2 duplicate
records by keeping 1 duplicate and 1 original as it is,how?

Answers were Sorted based on User's Feedback



if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and ..

Answer / mohamed zunu

create table sampletbl(id int,name varchar(100))

insert into sampletbl values(1,'aa')
insert into sampletbl values(1,'aa')
insert into sampletbl values(1,'aa')


with cte as(
select ROW_NUMBER() over (partition by id order by id) as r_no,* from sampletbl)
delete from cte where r_no>1
select * from sampletbl

Is This Answer Correct ?    9 Yes 1 No

if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and ..

Answer / siva raman

By using Rank function we can delete duplicate records in
tables.

Is This Answer Correct ?    6 Yes 3 No

if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and ..

Answer / amol maske

DELETE FROM tablename WHERE ROWID NOT IN(
SELECT MIN(ROWID)FROM tablename GROUP BY columnname);

Is This Answer Correct ?    5 Yes 4 No

if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and ..

Answer / dhananjay

The simplest way to eliminate the duplicate records is to
SELECT DISTINCT into a temporary table, truncate the
original table and SELECT the records back into the original
table. That query looks like this:

select distinct *
into #holding
from dup_authors

truncate table dup_authors

insert dup_authors
select *
from #holding

drop table #holding

Is This Answer Correct ?    0 Yes 0 No

if 3 duplicate records in a table,i want to delete 2 duplicate records by keeping 1 duplicate and ..

Answer / arun ashok

STEP 1 : Insert distinct value in the one new table.
STEP 2 : Delete the values from existing table.
STEP 3 : Again insert the values from new table to existing
table.

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More SQL Server Interview Questions

what is performance tunning in sql server ? explain.

1 Answers   Thomson Reuters,


can any one please send sql quries most used in applications.

2 Answers  


What are the types of user defined functions in sql server?

0 Answers  


what is hash table

3 Answers   ILFS, Teledata,


What do you mean by an execution plan?

0 Answers  






Explain activity monitors

0 Answers  


How to set a database state to offline in ms sql server?

0 Answers  


how to use DTS package in 2000,2005,2008 in sql server

0 Answers   Microsoft,


What is multi-statement table-value user-defined function?

0 Answers  


I am learning Testing, so i want to learn SQL also because SQL is important for Testing. I want to know which is best Institute in Ameerpet or SR Nagar or any other place in Hyd? Please help me.

7 Answers  


What is explicit cursors?

0 Answers  


Give an example of SQL injection attack ?

0 Answers   HAL,


Categories