Delete duplicate rows from a table without primary key by
using a single query
Table Employee
empname salary
A 200
B 300
A 200
C 400
D 500
D 500
Output should be
A 200
B 300
C 400
D 500
Answers were Sorted based on User's Feedback
Answer / b.v.rajaram
delete top (select count(*)-(select count(distinct empname )
from Employee) from Employee)from Employee
where a in (select distinct a from Employee)
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / v.krishnakumar
using the keyword distinct we can avoid the duplicate value
in our table,(ex) SELECT DISTINCT empname FROM Employee
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / arijit mandal
DELETE FROM Employee a
WHERE ROW_NUMBER() <>
( SELECT MIN( ROW_NUMBER() )
FROM Employee b
WHERE a.empname = b.empname
AND a.salary = b.salary)
| Is This Answer Correct ? | 0 Yes | 2 No |
Answer / jansi rani
SELECT EMPNAME,SAL FROM EMP GROUP BY EMPNAME,SAL
| Is This Answer Correct ? | 0 Yes | 4 No |
What are all new concepts in SQL Server 2008? That is Exactly Difference between 2005 to 2008
What is a unique key constraint?
Write a program to fetch first 10 records from a file?
1.how to find the dead lock in sql server? 2.How to fine the memory leaks in sql server? 3.suppose transaction log file increasing what action will take ?
Please explain what is “asynchronous” communication in sql server service broker?
Explain what is the difference between a local and a global temporary table?
Explain the dirty pages?
What is view in sql?
What is the difference between drop table and truncate table?
What is optimization and its types?
What is the difference function and stored procedure?
can an automatic recovery be initiated by a user? : Sql server administration
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)