0
Zend框架2聯盟選擇我有這樣的SQL代碼:與秩序
(SELECT `column1` FROM `table_1` WHERE `column2` > 2)
UNION
(SELECT `column1` FROM `table_2` WHERE `column2` < 10)
ORDER BY `column1` ASC;
如何做到這一點與Zend框架2?
Zend框架2聯盟選擇我有這樣的SQL代碼:與秩序
(SELECT `column1` FROM `table_1` WHERE `column2` > 2)
UNION
(SELECT `column1` FROM `table_2` WHERE `column2` < 10)
ORDER BY `column1` ASC;
如何做到這一點與Zend框架2?
Zend Framework 2 Zend \ Db \ Sql不提供聯合方法,但您必須自己寫或使用JOIN。
$sql = new Sql($this->adapter);
$select = $sql->select();
$select->from($this->table)
->join('table_1', 'table_2.column1 = table_1.column1');
$where = new Where();
$where->greaterThan('column2', 2) ; //youll have to add a and here with a lessThan
$select->where($where);
$statement = $sql->prepareStatementForSqlObject($select);
$result = $statement->execute();
老實說,我沒有嘗試這個例子,但至少應該給你一個想法。