How to delete duplicate records from a table?(for suppose in
a table we have 1000 Records in that we have 200 duplicate
Records , so ,how to findout that duplicate Records , how to
delete those Records and arranged into sequence order? one
more thing that there is no primary key at all)
Answers were Sorted based on User's Feedback
Answer / sneha
select distinct * from table into new_table;
delete table;
select * from new_table into table;
| Is This Answer Correct ? | 8 Yes | 6 No |
Answer / cp
DELETE FROM emp WHERE ROWID NOT IN(SELECT MAX(ROWID) FROM
emp GROUP BY empno)
| Is This Answer Correct ? | 2 Yes | 3 No |
Answer / smitha
;with empctc(empid,ename,sal,deptid,ranking)
as
(Select empid,ename,sal,deptid,ranking=Dense_rank() over (
partition by empid,ename,sal,deptid order by NEWID() asc)
from emp
)
delete * from empctc where ranking>1
| Is This Answer Correct ? | 2 Yes | 5 No |
Answer / sirisha
with numbered as(select rowno = row_number() over(partition
by empid order by empid),empname from employee)delete from
numbered where rowno > 1
| Is This Answer Correct ? | 1 Yes | 6 No |
Answer / pooja narang
We will get the duplicate records and insert them into a
new temp table by using below query:
select * into tmp_Employee
from Employee
having count(distinct *) > 1
Now delete the duplicate records from Employee table:
delete from Employee
having count(distinct *) > 1
Now insert the records from tmp_Employee to Employee table:
insert into Employee
select * from tmp_employee
drop table tmp_employee
| Is This Answer Correct ? | 4 Yes | 15 No |
explain the type of contraints
How do you delete duplicate records in sql server?
What is updatable resultset?
why we use cursor?
4 Answers CarrizalSoft Technologies, Melstar, TCS,
What is normalization of database? What are its benefits?
What language is sql server written in?
List out a number of the wants to setup a SQL Server failover cluster?
What are the types of subquery?
John exports information periodically from a microsoft sql server database to an oracle database what is the best way to do this?
define and explain the differences between clustered and non-clustered indexes.
What are entities and relationships?
What is the appropriate number of test cases that you can write on a database?
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)