我试图找到一种方法将这两个表连接在一起,我能够做到,但如果找到多个匹配的值,它会再次显示产品表中的所有内容.现在我试图将MySQL group_concat一起使用,以便能够在数组中的一个字段中列出所有tName但是我一直在使用MySQL收到错误:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘FROM (sp_product ) LEFT OUTER JOIN sp_product_type ON sp_product_type .`tCat’ at line 2
SELECT sp_product .name ,sp_product .price ,sp_product .perm_name ,sp_product .description ,GROUP_CONCAT(product_type.tName SEPARATOR FROM (sp_product ) LEFT OUTER JOIN sp_product_type ON sp_product_type .tCategory = sp_product .type WHERE perm_name = ‘bacon’
$this->db->select('product.name,product.price,product.perm_name,product.description,GROUP_CONCAT(product_type.tName SEPARATOR ',') as product_type.tName');
$this->db->from('product');
$this->db->where('perm_name',$this->uri->segment(2));
$this->db->join('product_type','product_type.tCategory = product.type','LEFT OUTER');
$query = $this->db->get();
我有什么想法我做错了吗?
最佳答案
似乎报价不当引起问题.
它应该是GROUP_CONCAT(product_type.tName SEPARATOR“,”)
试试以下:
$this->db->select('product.name,GROUP_CONCAT(product_type.tName SEPARATOR ",") as product_type.tName');
$this->db->from('product');
$this->db->where('perm_name',$this->uri->segment(2));
$this->db->join('product_type','LEFT OUTER');
$query = $this->db->get();
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|