Write a query to delete duplicate records in SQL SERVER
Answers were Sorted based on User's Feedback
Answer / dharmesh
your table look like this and want to delete duplicate
record
chandran 23
ranjith 24
chandran 23
delete top(1) from tablename where name='chandran' and
age=23
| Is This Answer Correct ? | 3 Yes | 28 No |
Create table info(comp_id int identity(101,1),comp_name
varchar(50))
insert into info values('Progressive Ltd.')
insert into info values('Progressive Ltd.')
insert into info values('EliResearch')
insert into info values('Patni')
insert into info values('Accenture')
insert into info values('Accenture')
select * from info
DELETE FROM info
WHERE comp_name IN
(SELECT comp_name FROM info
GROUP BY comp_name HAVING COUNT(comp_name) > 1)
| Is This Answer Correct ? | 12 Yes | 38 No |
Hi friends, please just try out this. This works fine for me.
We have lot of methods to do this. But using temp table,
drop the original table,retain the temp as orinial is not a
good pratice.
When u have large no of data it will affect ur performance.
DELETE FROM employee WHERE((SELECT eid,COUNT(eid) FROM
employee GROUP BY eid) > 1)
| Is This Answer Correct ? | 15 Yes | 46 No |
Answer / chandran.s
Table Name: Example
Name Age
chandran 23
ranjith 24
chandran 23
To delete one of the duplicate records use following query
delete from example where age in(select age from example
group by age having count>1)
| Is This Answer Correct ? | 13 Yes | 46 No |
Answer / chandran
There is a table like this: tablename: example
Name Age
chandran 23
ranjith 24
chandran 23
In this table the name:chandran and age:23 are the
duplicate records .so we need to delete this using this
sql statements
delete from example group by name,age having count>1
| Is This Answer Correct ? | 37 Yes | 107 No |
List down some advantages of sql stored procedure?
How to verify a login name with sqlcmd tool?
What is row_number()?
What is a Trace frag?Where can we use this?
Why do we need normalization?
Do you know what are various aggregate functions that are available?
Is the order of columns in the set clause important in ms sql server?
What is de-normalization and what are some of the examples of it?
What are the types of resultset?
What is the purpose of sql profiler in sql server?
What is filter index?
What are the requirements on sql server network connections?
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)