【发布时间】:2014-07-07 22:18:59
【问题描述】:
如何执行下面的查询
select * from table1 union select * from table2
在 zend-framework2 中我在哪里使用 tablegateway?在zf2的文档中,他们没有给出关于联合查询的任何细节。
【问题讨论】:
标签: postgresql zend-framework2 union
如何执行下面的查询
select * from table1 union select * from table2
在 zend-framework2 中我在哪里使用 tablegateway?在zf2的文档中,他们没有给出关于联合查询的任何细节。
【问题讨论】:
标签: postgresql zend-framework2 union
试试-
$select1 = new Select('table1');
[.... rest of the code ....]
$select2 = new Select('table2');
[.... rest of the code ....]
$select1->combine($select2); //This will create the required SQL union statement.
要获得两个表的计数,您必须使用一些 SQL 而不是 tableGateway -
$sql = new Sql($this->tableGateway->adapter);
$select_string = $sql->getSqlStringForSqlObject($select1);
$sql_string = 'SELECT * FROM (' . $select_string . ') AS select_union';
$statement = $this->tableGateway->adapter->createStatement($sql_string);
$resultSet = $statement->execute();
$total_records = count($resultSet);
$resultSet 给出数据。
$total_records 给出总数。记录。
【讨论】:
$where 转换为字符串并追加的方法。我想现在,您将不得不在原始 SQL 中编写条件并追加。