【问题标题】:Zend Framework: Zend_Db_Select - how to join custom subquery table?Zend 框架:Zend_Db_Select - 如何加入自定义子查询表?
【发布时间】:2011-08-13 03:06:16
【问题描述】:
$select->joinRight(array('i' => '(SELECT * FROM images ORDER BY image_id)'),'i.ad_id = '. $main .'.id',$imarray);

这样不行。子查询进入引号。

这样:

RIGHT JOIN `(SELECT * FROM images ORDER BY image_id)` AS `i` ON i.ad_id = a.id

谢谢 ;)

【问题讨论】:

    标签: zend-framework


    【解决方案1】:

    使用

    $select->joinRight(
        array('i' => new Zend_Db_Expr('(SELECT * FROM images ORDER BY image_id)')),
        'i.ad_id = '. $main .'.id',
        $imarray
    );
    

    【讨论】:

    • 我是这么想的,但我心情很好。这就是为什么它不是 RTFM :D
    • 顺便说一句:我认为如果您将字符串替换为 Zend_Db_Select 对象,它也会起作用....
    【解决方案2】:

    我觉得这更容易阅读和导航......

          $sub = $this->select()
                ->setIntegrityCheck(false)
                ->from(array('i' => 'images'), array('*'))
                ->order('i.image_id');
    
    $select = $this->select()
                 ->setIntegrityCheck(false)
                 ->from(array('m' => 'MAIN_TABLE'), array('*'))
                 ->joinRight(array('i' => $sub), 'i.ad_id = m.id', array('*'));
    
       return $this->select($select);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多