Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a table which has duplicant records, i want to delete the records.


Table:

EMP_ID EMP_NAME EMP_ADD
1 basha bnlg
1 basha s kyd
2 pavan hyd
3 inayat bnlg
3 shaik bnlg
3 santu hyd


OutPut:

EMP_ID EMP_NAME EMP_ADD
1 basha bnlg
2 pavan hyd
3 inayat bnlg


Can any one help plz

Regards,
Basha,
Posted

You can try this[^] solution out as well.
 
Share this answer
 
--fetch distinct record from table name
select distinct(EMP_ID),EMP_NAME,EMP_ADD from TableName
--create a temprory table here
create table #TempTableName
(EmpId int,Name varchar(50),Address varchar(200))
--insert unique values into temprory table 
insert into #TempTableName (EMP_ID,EMP_NAME,EMP_ADD)select distinct(EMP_ID),EMP_NAME,EMP_ADD from TableName
--Check insert values into temp table
select * from #TempTableName
--truncate main table
truncate table TableName
--insert values from temp table into main table
insert into TableName(EMP_ID,EMP_NAME,EMP_ADD)select EMP_ID,EMP_NAME,EMP_ADD #TempTableName
--check latest record in main table
select * from TableName
 
Share this answer
 
v2
Go through this link.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900