Php 如何在codeigniter中查找重复记录
我正在尝试编写一个查询,以在Codegigniter中查找重复的行,但它不起作用。 我的代码(模型) 只返回第一条记录 重复的数据在myTable中,我想找到那些重复的数据Php 如何在codeigniter中查找重复记录,php,mysql,duplicates,codeigniter-3,Php,Mysql,Duplicates,Codeigniter 3,我正在尝试编写一个查询,以在Codegigniter中查找重复的行,但它不起作用。 我的代码(模型) 只返回第一条记录 重复的数据在myTable中,我想找到那些重复的数据 SELECT username, email, COUNT(*) FROM users GROUP BY username, email HAVING COUNT(*) > 1 分组并找到它 $this->db->select('*'); $this->db->from('myTable sr
SELECT username, email, COUNT(*)
FROM users
GROUP BY username, email
HAVING COUNT(*) > 1
分组并找到它
$this->db->select('*');
$this->db->from('myTable sr');
$this->db->join('table2 s','sr.st_id=s.st_id');
if($conn!='')
{
$this->db->where($conn);
}
if($identity!='')
{
$where = "(s.student_id = '$identity' OR s.name LIKE '%$identity%')";
$this->db->where($where);
}
if($duplicate != '')
{
$this->db->having('COUNT("sr.st_id")>1');
$this->db->group_by('sr.st_id');
}
if($limit_row!='')
{
$this->db->limit($limit_row,$starting);
}
$query = $this->db->get();
var_dump($this->db->last_query($query));exit;
return $query->result_array();
分组并查找它请提供数据。没有它,我们无法检查查询。此语句不清晰,有一个bug=>$this->db->join('table2s','sr.st_id=s.st_id');rs','rs.resultState_id=sr.result_state');我编辑的代码,目标是如何找到重复的。请提供一个数据。没有它,我们无法检查查询。此语句不清晰,有一个bug=>$this->db->join('table2s','sr.st_id=s.st_id');rs','rs.resultState_id=sr.result_state');我编辑了代码,目标是如何找到重复的。它跳过重复的记录,但我想找到重复的记录。Mona Bishnoit跳过重复的记录,但我想找到重复的记录。Mona Bishnoit只显示一条记录,我想显示所有记录。我的意思是一条记录中有多少重复的记录它只显示一条记录,我想全部展示。我的意思是一张唱片有多少个副本
$this->db->select('*');
$this->db->from('myTable sr');
$this->db->join('table2 s','sr.st_id=s.st_id');
if($conn!='')
{
$this->db->where($conn);
}
if($identity!='')
{
$where = "(s.student_id = '$identity' OR s.name LIKE '%$identity%')";
$this->db->where($where);
}
if($duplicate != '')
{
$this->db->having('COUNT("sr.st_id")>1');
$this->db->group_by('sr.st_id');
}
if($limit_row!='')
{
$this->db->limit($limit_row,$starting);
}
$query = $this->db->get();
var_dump($this->db->last_query($query));exit;
return $query->result_array();