【发布时间】:2011-11-04 14:06:26
【问题描述】:
下面的查询代表我正在尝试做的事情,我需要拉入 blog_posts 列表并加入用户表。
它还在做的是从 blog_updates_pictures 中提取一个随机的“picture_filename”。它需要 blog_updates 作为连接来引用 blog_update_id。
我现在想做的也是为每个 blog_post 计算 blog_updates 的数量。我认为这是一个子查询,但每个实现都失败了。让 count 接受参数也很好(即 blog_updates where date = ?)。此外,blog_post 可能没有更新或图片。
$select = $db->select ();
$select->from ( array ('b' => 'blog_posts' ), array('headline', 'date_created'));
$select->join ( array ('u' => 'users' ), 'u.user_id = b.user_id', array ( 'email' ) );
$select->joinLeft ( array ('bu' => 'blog_updates' ), 'bu.blog_id = b.blog_id', array () );
$select->joinLeft ( array ('bup' => 'blog_updates_pictures' ), 'bu.blog_update_id = bup.blog_update_id', array ('picture_filename' ) );
谁能给我指路?
谢谢
【问题讨论】:
-
查看这个答案以了解如何使用 Zend_Db_Select stackoverflow.com/questions/5604872/nested-select-using-zend-db/…创建子查询
-
提供一个示例架构+数据,我会提供一个解决方案。
标签: php mysql database zend-framework