Delete duplicate records from the table?(Table must have
unique id)
Answers were Sorted based on User's Feedback
Answer / dinesh kumar
delete from emp where id Not in(select max(id) id from emp
group by name having count(id)>1)
Is This Answer Correct ? | 22 Yes | 9 No |
Answer / lince
DELETE
FROM MyTable
WHERE ID IN
(
SELECT MAX(ID)
FROM MyTable
GROUP BY DuplicateColumn1 HAVING COUNT(ID)>1
)
Is This Answer Correct ? | 4 Yes | 2 No |
Answer / kk
DELETE
FROM MyTable
WHERE ID NOT IN
(
SELECT MAX(ID)
FROM MyTable
GROUP BY DuplicateColumn1, DuplicateColumn2, DuplicateColumn3)
Is This Answer Correct ? | 7 Yes | 7 No |
Answer / naren
delete id from table where id in(select id from table having count(id)>1)
Is This Answer Correct ? | 1 Yes | 2 No |
Answer / krishna
select *
from mytable b
join
(
select Duplicatecolumn,MAX(id) id
from mytable
group by Duplicatecolumn
) b1 on b.Duplicatecolumn = b1.Duplicatecolumn
where b.id <> b1.id
Is This Answer Correct ? | 0 Yes | 1 No |
Answer / brijesh darmwal, sandhya
DELETE FROM [MyDb].[dbo].[sandhya]
WHERE id
IN
(SELECT id
FROM
(SELECT MAX(id) as id,name,addr
FROM [MyDb].[dbo].[sandhya] GROUP BY name,addr having
count(id)>=2)
Tmp)
Is This Answer Correct ? | 7 Yes | 16 No |
please tell me the query to get details of the employee having the second largest salary
If we delete pack Spec what will be the status of pack Body ?
How to find out what is the default collation in a database?
What is the filtered index?
How to update values in a table with update statements in ms sql server?
sql database suspect We have a sql database that is showing as suspect. How can we recover?
I have to display ten columns values from diffrent ten tables. how many joins are require?
10 Answers CarrizalSoft Technologies, HCL,
 Explain what is sql override for a source taLle in a mapping?
What is the simplest way to create a new database in ms sql server?
What is a subquery in a select query statement in ms sql server?
Relational calculus is what type of language?
Do you know what are the restrictions that views have to follow?