我必须在zend-framework2中编写以下查询
select count(*) from
(
select * from table1
UNION
select * from table2
)
as a
where col1 = condition1 and col2 = condition2;
我使用 -
完成了两个表的联合$select1 = new Select('table1');
$select2 = new Select("table2");
$select1->combine($select2);
我不知道在完成两个表的并集以及如何获取数据之后如何给别名。
答案 0 :(得分:0)
$select1->combine($select2);
-
$sql = new Sql($this->tableGateway->adapter);
$select_string = $sql->getSqlStringForSqlObject($select1);
$sql_string = 'SELECT * FROM (' . $select_string . ') AS select_union WHERE col1 = condition1 and col2 = condition2';
$statement = $this->tableGateway->adapter->createStatement($sql_string);
$resultSet = $statement->execute();
$total_records = count($resultSet);
$resultSet
提供数据。
$total_records
给出总数。记录。