php查找重复的记录

 1.查找有一个字段值重复的sql语句

 select username,count(*) from userinfo group by username having count(*)>1 ;

2.查找有一个字段值重复的php脚本

<?php
$cn=mysql_connect("localhost","root","");
$db=mysql_select_db("test");
$sql="select distinct username from userinfo";
$query=mysql_query($sql);
while($row=mysql_fetch_array($query)){
 echo $row["username"]."---";
 $my_sql="select count(*) from userinfo where username='".$row["username"]."'";
 echo mysql_result(mysql_query($my_sql),0);
 echo "<br/>";
}
?>

3.查找有两个字段值重复的sql语句

Select  username,age,Count(*) From userinfo Group By username,age Having Count(*)>=1;

4、查找每天都发表了多少篇文章并且是同一类别的

Select logclassid,date(datetime),Count(*) From log Group By logclassid,date(datetime) Having Count(*)>=1 order by date(datetime) desc;

5、查找有一个字段值重复,其他项

select * from log where id not in(select id from log group by classid having count(*)>=1);

    A+
发布日期:2021年07月14日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: