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



Delete duplicate rows from a table without primary key by using a single query Table Employee em..

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

Delete duplicate rows from a table without primary key by using a single query Table Employee em..

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

Delete duplicate rows from a table without primary key by using a single query Table Employee em..

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

Delete duplicate rows from a table without primary key by using a single query Table Employee em..

Answer / jansi rani

SELECT EMPNAME,SAL FROM EMP GROUP BY EMPNAME,SAL

Is This Answer Correct ?    0 Yes 4 No

Post New Answer

More SQL Server Interview Questions

explain different types of cursors? : Sql server database administration

0 Answers  


Can we use pragma autonomous_transaction in trigger?

0 Answers  


What is “asynchronous” communication in sql server service broker?

0 Answers  


what's the difference between delete table and truncate table commands? : Sql server database administration

0 Answers  


What are the different ways of moving data/databases between servers and databases in SQL Server?

3 Answers   HCL,






Explain transaction server isolation?

0 Answers  


How do I view a stored procedure in sql server query?

0 Answers  


How do you rename a table in sql server?

0 Answers  


how to rest identity columns in sql server

3 Answers   Matrix,


WHAT OPERATOR PERFORMS PATTERN MATCHING?

2 Answers   CarrizalSoft Technologies, CTS,


How to remove duplicate rows from table except one?

0 Answers  


What does Master database contains?

0 Answers   Abacus,


Categories