问题描述
我有一个包含重复记录的表,我想删除记录.
表格:
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
输出:
EMP_ID EMP_NAME EMP_ADD
1 basha bnlg
2 pavan hyd
3 inayat bnlg
有人可以帮忙吗?
问候,
Basha,
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,
推荐答案
--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
这篇关于如何从表中删除重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!