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 |
How to enforce security in sql server? : sql server security
What are the different types of locks in the database?
What are cursors stored procedures and triggers?
Explain the use of containers in ssis and also their types?
You have a table ‘test’ which is a copy of northwind employee table you have written a trigger to update the field ‘hiredate’ with the current date
What is instead of dml trigger?
What are system databases in ms sql server?
What is the purpose of UPDATE STATISTICS?
Write a query for primary key constraint with identity key word?
How do you connect 100 files as a flat file sources in one package of SSIS?
Is there any difference between primary key and unique with the not null condition?
Difference between report and query parameter. Why do we need different type of parameter?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)