如何从表中删除重复记录 [英] how to delete duplicant records from a table

查看:88
本文介绍了如何从表中删除重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个包含重复记录的表,我想删除记录.


表格:

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,

推荐答案

您可以尝试 [ ^ ]解决方案.
You can try this[^] solution out as well.


--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


浏览

这篇关于如何从表中删除重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆