php - 代码点火器。查询重复结果

标签 php mysql codeigniter

我有两张 table 。

pre_order_details

  id     pre_order_id     product_id   product_quantity

这里 pre_order_id 和 Product_id 是外键,可以有重复的值。

Recieve_Pre_Order

  id    pre_order_id  product_id quantity_recieved

这里 pre_order_id 和 Product_id 是伪造 key 并且可以有重复。

我想给 pre_order_id 并获取所有相关数据。

这是我的查询

$this->db->select('*');
    $this->db->from('pre_order_details');

$this->db->join('recieve_pre_order', 'recieve_pre_order.product_id = pre_order_details.product_id');


$this->db->where('pre_order_details.pre_order_id',$pre_order_id);
return $this->db->get(); 

它返回重复的数据。有人可以指出我的错误,甚至是我的数据库设计吗?

最佳答案

在选择查询中应用 DISTINCT 语句。 $this->db->select('*') 使用特定列

$this->db->select('DISTINCT(pre_order_id),other column name);

关于php - 代码点火器。查询重复结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42296599/

相关文章:

mysql - 类别和子类别 MySQL

php - 使用 amazon s3 下载图像而不是在浏览器中显示 - Codeigniter

javascript - <?= 标签在 codeigniter 版本 2.1.0 中不起作用

codeigniter - 我如何在 codeigniter 中创建一个虚荣网址

PHP GD 库,将 2 张图像并排转换为 1 张

php - Azure - 从 PHP 为 Blob 生成 SAS token

mysql - 最大化 MySQL 分析服务器的内存使用

javascript - Php 正则表达式 到 javascript 正则表达式

session - PHP:在 session 中断 session 中存储闭包

mysql - 使用逗号分隔的字符串加入字段