要求 删除表中某字段重复记录,保留一条:
-- 做法,借用临时表
create table user_temp as
select a.name1,a.password1,MAX(a.ROWID) dataid from user_test1 a GROUP BY a.name1,a.password1;
-- 删除 重复记录
delete from user_test1 a
where a.rowid !=
(
select b.dataid from user_temp b
where a.name1 = b.name1 and
a.password1 = b.password1
);
commit;
有好的见意吗?
-- 做法,借用临时表
create table user_temp as
select a.name1,a.password1,MAX(a.ROWID) dataid from user_test1 a GROUP BY a.name1,a.password1;
-- 删除 重复记录
delete from user_test1 a
where a.rowid !=
(
select b.dataid from user_temp b
where a.name1 = b.name1 and
a.password1 = b.password1
);
commit;
有好的见意吗?
删除重复记录技巧
本文介绍了一种使用临时表的方法来删除数据库表中的重复记录,并保留其中一条。通过创建临时表并利用 GROUP BY 和 MAX 函数确定唯一记录,再通过 DELETE 语句结合子查询找出并删除重复的数据。
1180

被折叠的 条评论
为什么被折叠?



