create table empp(id int identity ,name varchar(30))
insert into empp values('bhanu')
select * from empp
-- for selecting duplicate record
select name ,count(*) cnt from empp e group by e.name having count(*) >1
-- for selecting non-duplicate record
--with having
delete from empp where id in (select max(id) from empp group by name having count(*)>1)
--without having
delete from empp where id not in (select max(id) from empp group by name)
DELETE FROM emp WHERE ID NOT IN (SELECT MIN(ID) FROM emp GROUP BY FName)
delete from tableName where UniqueColumn NOT IN (select MIN(UniqueColumn) from tableName GROUP BY DuplicateRecoedColumn/DeletedDuplicateColumn)
DELETE FROM emp WHERE ID NOT IN (SELECT MIN(ID) FROM emp GROUP BY FName)
delete from tableName where UniqueColumn NOT IN (select MIN(UniqueColumn) from tableName GROUP BY DuplicateRecoedColumn/DeletedDuplicateColumn)
No comments:
Post a Comment