我有两张 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/