簡體   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