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 sql server schema compare? How we can compare two database schemas?
What are the advantages of passing name-value pairs as parameters?
Is it possible to import data directly from t-sql commands without using sql server integration services? If so, what are the commands?
How to find the version of sql server? : sql server database administration
What is a cube? : sql server analysis services, ssas
What are the system database in sql server 2005?
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
Can a function call a stored procedure in sql server?
what is a default tcp/ip socket assigned for sql server? : Sql server database administration
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?
What is a result set object returned by mssql_query()?
How do you delete duplicate rows in sql server?