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 |
What is the most common type of join?
In the below query i have performed the commit transaction statement but still the values after the save are not saved. Can you please let me know why are the statements after save are rolled back even after commiting the data. help me with the understanding declare @trans2 varchar(10)='transaction2' begin transaction @trans2 insert into emp values(100,'xy',600); save transaction @trans2 insert into emp values(200,'pq',700); insert into emp values(300,'pq',800); commit transaction @trans2 rollback tran @trans2
What do you understand by the analysis services in sql server?
How many triggers are possible per table?
how to find the second salary?
how we can count records as a group of days like sum of records for(four mondays),(four tuesday)........ in a month. group the column for weekdays.
what is a default tcp/ip socket assigned for sql server? : Sql server database administration
Why I am getting "the microsoft .net framework 2.0 in not installed" message?
Explain time data type in sal server 2008?
What are the properties of sub-query?
Differnce between sel server 2000 and 2005
How to download and install the scaled-down database adventureworkslt?