此查询搜索产品,有些产品名称相同但尺寸不同或类似。
如何在此代码中添加Select Distinct?
private function query_products($category = 1, $id = NULL, $search = NULL){
$this->db->select('PP.*');
$query= $this->db->from("PLUGIN_PRODUCTS PP");
//->where('PCP.COUNTRY', $country);
if($search == NULL):
$query = $query->where('PP.PRODUCT_CATEGORY', $category);
else:
$query = $query->like('PP.PRODUCT_NAME', $search)
->or_like('PP.PRODUCT_DESCRIPTION', $search)
->or_like('PP.PRODUCT_CODE', $search)
->group_by("PP.ID");
endif;
if(!empty($id)):
$query = $query->where('PP.ID', $id);
endif;
return $query;
}
答案 0 :(得分:1)
更改此
->group_by("PP.ID");
到
->group_by("PP.PRODUCT_NAME , PP.PRODUCT_SIZE");