假設我有2個表GROUP_CONCAT與JOINLEFT在Zend的Db的選擇
articles
id title
1 Article 1
2 Article 2
Images
id article_id image
1 1 a.png
2 1 b.png
3 2 c.png
4 2 d.png
所有我想要的是retreive所有文章與自己的形象。
例如:
article_id title images
1 Article 1 a.png, b.png
2 Article 2 c.png, d.png
我怎麼能做到這一點與Zend_Db_Select對象?
我想是這樣的,但沒有運氣:
$select = $this->getDbTable()->select()->setIntegrityCheck(false)->distinct();
$select->from(array('a'=>'articles'))
->joinLeft(array('i'=>'images'),'i.article_id=a.id',array('images'=> new
Zend_Db_Expr('GROUP_CONCAT(i.image)')));
它返回僅僅只有1行其「圖像」字段包含兩篇文章的圖像。
article_id title images
1 Article 1 a.png, b.png, c.png, d.png
我在做什麼錯在這裏?
哪裏是group by子句? – 2012-04-10 09:42:33