php - 如何去除mysql中重复的数据?

标签 php mysql codeigniter

这是我的明细表:

enter image description here

这是我的联系人表:

enter image description here

details 表中有两行,contact 表中有 4 行(每个 details 有 2 行)。当我使用连接查询时,我得到 4 个结果行,但我只想要 2 行(一行详细信息行和一个相应详细信息的联系人)。
我的查询:

$this->db->select('*');
$this->db->from('dots_center_detail');
$this->db->join('dots_center_contact', 'dots_center_contact.registration_id = dots_center_detail.registration_id','left');

最佳答案

试试这个

$this->db->query("
  SELECT DISTINCT dots_center_detail.registration_id,  dots_center_contact.contact
  FROM dots_center_detail
  LEFT JOIN dots_center_contact ON dots_center_contact.registration_id = dots_center_detail.registration_id
")

关于php - 如何去除mysql中重复的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45719633/

相关文章:

php - Doctrine2 多对多关系不保存

MySQL JOIN ON 子查询?

php - 如何通过搜索用户并单击其链接来查看用户的个人资料

php - 为标签命名并调用 if isset 函数

php - undefined variable CodeIgniter?

mysql - 使用 Codeigniter 比较同一行和同一表中的 2 个值

php - 查询 PDO 中的绑定(bind)参数错误

php - 有没有可以帮助我正确引用 SQL 字符串的服务?

php - 使用 CodeIgniter 从 MySQL 中检索不同的结果

php - 函数的 return 语句未按预期工作