我想找到一種方法將這兩個表連接起來,這是我能夠做到的,但是如果它發現多個匹配的值,它會再次顯示產品表中的所有內容。現在我試圖使用MySQL GROUP_CONCAT在一起,能夠列出所有TNAME在一個領域的陣列中,但我不斷收到一個錯誤與MySQL:CodeIgniter GROUP_CONCAT並加入
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 JOINsp_product_type
ONsp_product_type
.`tCat' at line 2SELECT
sp_product
.name
,sp_product
.price
,sp_product
.perm_name
,sp_product
.description
, GROUP_CONCAT(product_type.tName SEPARATOR FROM (sp_product
) LEFT OUTER JOINsp_product_type
ONsp_product_type
.tCategory
=sp_product
.type
WHEREperm_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();
任何想法,我做錯了?
也許應該傳遞一個'false'參數到'select' - 因爲錯誤的保護算法... – uzsolt 2012-02-17 10:09:46
我仍然得到一個錯誤:你的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以在'sp_product'附近使用正確的語法)LEFT OUTER JOIN'sp_product_type' ON'sp_product_type'.''tCategory''at line 1 – Claremont 2012-02-17 20:18:14