繁体   English   中英

Codeigniter。 查询重复结果

[英]Codeigniter . Query Duplicates the result

我有两张桌子。

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是forgin键,可以重复。

我想给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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM