Codeigniter。查询复制结果

时间:2017-02-17 11:18:25

标签: php mysql codeigniter

我有两张桌子。

pre_order_details

  id     pre_order_id     product_id   product_quantity

这里pre_order_id和product_id是forign键,可以有重复的值。

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(); 

它返回重复的数据。有人指出我的错误甚至我的数据库设计。

1 个答案:

答案 0 :(得分:1)

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

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