消除MySQL结果中的重复数据

消除MySQL结果中的重复数据

问题描述:

This is a part of MySQL query in CodeIgniter and when I am echoing the sub_product it duplicates the same product name.Is there anything I can do to eliminating duplicate data other than using $this->db->order_by();.

Thanks!!! Ann

   $this->db->select(array(            
            'GROUP_CONCAT(tbl_sub_products.sub_product_name SEPARATOR "<th>" ) as sub_product'
        ));

这是CodeIgniter中MySQL查询的一部分,当我回显 sub_product strong>时 重复相同的产品名称。除了使用 $ this-&gt; db-&gt; order_by(); strong>。 p>

谢谢!!! Ann p>

  $ this-&gt; db-&gt; select(array(
'GROUP_CONCAT(tbl_sub_products.sub_product_name SEPARATOR“&lt; th&gt;”))  as sub_product'
)); 
  code>  pre> 
  div>

You should use group_by():

$this->db->select(array(            
            'GROUP_CONCAT(tbl_sub_products.sub_product_name SEPARATOR "<th>") as sub_product'
))->group_by("sub_product_name");

I'm not entirely sure on the name of the product name column, so you will have to change that.