Zend Frameworks 1.12:如何在不返回结果的情况下加入自定义子查询 table

Zend Frameworks 1.12: how to join custom subquery table without returning results

我需要使用 Zend Framework 1.12 创建以下查询(这只是一个示例)作为更大查询的一部分:

SELECT `s`.* 
FROM `s`
INNER JOIN SELECT id FROM table where id = 13 AS `t`

这是我的尝试:

$query = $this->getDbTable()->select()
        ->from($this->getDbTable(), array('*'))
        ->join(array('t' => new Zend_Db_Expr('(SELECT id FROM tables where id = 13)')), array())
        ->setIntegrityCheck(false);

然而,这是输出:

SELECT `students`.*, `t`.* 
FROM `students`
INNER JOIN SELECT id FROM tables where id = 13 AS `t`

我不需要 select 中的 t.*,因为 t table 将在复杂查询中以其他方式使用。

您知道如何不 select t.* 但仍然使用子查询进行内部联接吗?

Zend_Db_Select->join 命令是 two/three 参数的构建。

  • table 姓名(可能带有别名)
  • 部分(ON table1.a = table2.a..)
  • 以及您想要 select 的列(如果您在此处未定义任何参数,您最终会 select 所有可能的字段 "t`.*")

在您的查询中,您缺少最后一个参数。如果您为联接分配另一个参数(参见下面的示例),您应该只从 ->from(... 部分的 table 获得结果。

->join(array('t' => new Zend_Db_Expr('(SELECT id FROM tables where id = 13)')), array(), array())