易截截图软件、单文件、免安装、纯绿色、仅160KB

MySQL重复记录 查询及删除

查询及删除重复记录的方法
(一)
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>1)
3、查找表中多余的重复记录(多个字段)
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)
and rowid not in (select min(rowid) from vitae group by peopleId,seq having count(*)>1)
(二)
比方说
在A表中存在一个字段“name”,
而且不同记录之间的“name”值有可能会相同,
现在就是需要查询出在该表中的各记录之间,“name”值存在重复的项;
Select Name,Count(*) from A Group By Name Having Count(*) > 1
如果还查性别也相同大则如下:
Select Name,sex,Count(*) from A Group By Name,sex Having Count(*) > 1
(三)
方法一
declare @max integer,@id integer
declare cur_rows cursor local for select 主字段,count(*) from 表名 group by 主字段 having count(*) >; 1
open cur_rows
fetch cur_rows into @id,@max
while @@fetch_status=0
begin
select @max = @max -1
set rowcount @max
delete from 表名 where 主字段 = @id
fetch cur_rows into @id,@max
end
close cur_ro


相关文档:

Mysql LOAD DATA命令的相关事项

1.在WINDOW下,记录数据的文本文件必须不能以中文命名(命令行界面无法输入中文),且需保存在磁盘根目录下。
2.字段值之间必须要以LOAD DATA命令中指定的分隔符分隔,默认为TAB,否则不识别,造成该字段值为NULL。
3.值为空的字段,在文本文件里可以设为空,也可以设为\N.
4.WINDOW下,不加"LINES TERMINATED BY ' ......

更改mysql数据库编码为GBK

刚刚安装完mysql后
从cmd中进入mysql数据库
命令行中输入:
mysql -uroot -p123
进入mysql数据库中
命令行中输入:
status;
查看当前数据库中的编码
如下:
--------------
mysql  Ver 14.12 Distrib 5.1.7-beta, for Win32 (ia32)
Connection id:       &nb ......

Red Hat enterprise linux 5 mysql安装步骤

一、安装服务器端
(1)、在有两个rmp文件的目录下运行如下命令:
[root@test1 local]# rpm -ivh MySQL-server-5.0.26-0.i386.rpm
显示如下信息:
warning: MySQL-server-5.0.26-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing……       ##################################### ......

php mysql回滚示例

首先,建InnoDB类型的表,才能支持事务
$handler = mysql_connect('localhost', '', '');
mysql_select_db('test');
mysql_query('SET AUTOCOMMIT=0'); // 设置为不自动提交查询
mysql_query('START TRANSACTION'); // 开始查询,这里也可以使用BEGIN
mysql_query("INSERT INTO users VALUES ('ccc')");
mysql_query( ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号