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