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 is buffer cash in sql server?
What happens when transaction log is full?
Can you explain what is sql server english query?
How to enter comments in transact-sql statements?
What is the difference between 2-Tier architecture and 3-Tier architecture
15 Answers CTS, MCN Solutions, Oracle,
Can we add a cpu to sql server?
Why use triggers?
What stored by the model? : sql server database administration
What is the difference between a check constraint and a rule?
What is normalization of database?
Other than truncate statement, which other command can by-pass the trigger on the tables?
What is user defined stored procedures?