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

What is sql server schema compare? How we can compare two database schemas?

0 Answers  


What are the advantages of passing name-value pairs as parameters?

0 Answers  


Is it possible to import data directly from t-sql commands without using sql server integration services? If so, what are the commands?

0 Answers  


How to find the version of sql server? : sql server database administration

0 Answers  


What is a cube? : sql server analysis services, ssas

0 Answers  






What are the system database in sql server 2005?

0 Answers  


Hi, I have a table A which has four rows as follows Table A ------- empname salary ------- ------ A 1000 B 2000 C 3000 A 1000 B 2000 D 5000 I need the following output: empname salary ------- ------ A 1000 A 1000 B 2000 B 2000 Thanks in advance

10 Answers   IBM,


Can a function call a stored procedure in sql server?

0 Answers  


what is a default tcp/ip socket assigned for sql server? : Sql server database administration

0 Answers  


how would you write a sql query to compute a frequency table of a certain attribute involving two joins? What changes would you need to make if you want to order by or group by some attribute? What would you do to account for nulls?

0 Answers   Facebook,


What is a result set object returned by mssql_query()?

0 Answers  


How do you delete duplicate rows in sql server?

0 Answers  


Categories