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_rows
set rowcount 0
相关文档:
远程连接mysql速度慢的解决方法
http://www.xishuiw.com
PHP 远程连接MYSQL速度慢,有时远程连接到MYSQL用时4-20秒不等,本地连接MYSQL正常,出现这种问题的主要原因是,默认安装的MYSQL开启了DNS的反向解析,在MY.INI(WINDOWS系统下)或MY.CNF(UNIX或LINUX系统下)文件的[mysqld]下加入skip- name-resolve这一句。连接mysq ......
我的系统是redhat as5 建议大家完全安装,以免安装时缺少相关的编译器等等。
一、安装mysql(mysql-5.0.21.tar.gz)
# tar zxf mysql-5.0.21.tar.gz
# cd mysql-5.0.21
#./configure --prefix=/usr/local/mysql --sysconfdir=/etc --localstatedir=/var/lib/mysql/
说明:
#prefix=/usr/lo ......
1、mysql编译参数:
#cat /usr/local/mysql/bin/mysqlbug|grep configure
# This is set by configure
CONFIGURE_LINE="./configure '--prefix=/usr/local/mysql' '--with-openssl' '--enable-thread-safe-client' '--enable-local-infile' '--with-charset=gbk' '-with-extra-charsets=gb2312,gbk'"
表示编译中支持ope ......
1 modify the /etc/mysql/my.cnf
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
#
you see the bind-address, comment it. 注掉它 ......
语法:
/usr/local/mysql/bin/mysqladmin -u username -p newpassword
系统会提示您输入旧密码:
按Enter后,系统将旧的密码改成newpassword,
注意newpassword不是命令,是一个字串,就是新密码的字串,你可以更改成其它的.
-u后面跟着是用户名,就是你所要更改的用户名. ......