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
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 |
Answer / siva raman
By using Rank function we can delete duplicate records in
tables.
Is This Answer Correct ? | 6 Yes | 3 No |
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 |
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 |
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 |
Can two tables share a primary key?
Explain triggers?
What is sql server locking?
What are the disadvantages of primary key and foreign key in SQL?
What are date and time data types in ms sql server?
How to stop a loop early with break statements in ms sql server?
You are designing a database for your human resources department in the employee table, there is a field for social security number, which cannot contain null values if no value is given, you want a value of unknown to be inserted in this field what is the best approach?
Define inner join in sql server joins?
What is the difference between two queries: 1. SELECT * FROM table WHERE 1=1; 2. SELECT * FROM table
where do you use Isolations?give me some exmpale?
What is the role that is required for killing a process What is the role that is required for creating a linked server
1 Answers CarrizalSoft Technologies, IBM,
what is database replicaion? : Sql server database administration