mysql – Zend 2中两个表的联合
作者:互联网
我想在zf2中使用where子句将两个表联合起来: –
table1 app_followers
table2 app_users
条件可能是什么
并按updated_date排序.
请让我知道zend 2的查询.
谢谢..
解决方法:
使用UNION是ZF2:
使用ZF2专用类Combine Zend\Db\Sql\Combine
new Combine(
[
$select1,
$select2,
$select3,
...
]
)
使用组合的详细示例如下:
$select1 = $sql->select('java');
$select2 = $sql->select('dotnet');
$select1->combine($select2);
$select3 = $sql->select('android');
$selectall3 = $sql->select();
$selectall3->from(array('sel1and2' => $select1));
$selectall3->combine($select3);
$select4 = $sql->select('network');
$selectall4 = $sql->select();
$selectall4->from(array('sel1and2and3' => $selectall3));
$selectall4->combine($select4);
$select5 = $sql->select('dmining');
$selectall5 = $sql->select();
$selectall5->from(array('sel1and2and3and4' => $selectall4));
$selectall5->combine($select5);
这相当于UNION的普通SQL查询:
SELECT * FROM java
UNION SELECT * from dotnet
UNION SELECT * from android
UNION SELECT * from network;
UNION SELECT * from dmining;
我希望它有所帮助.
标签:mysql,zend-framework2,zend-framework,zend-db,zend-framework3 来源: https://codeday.me/bug/20190527/1162238.html