Yii2.0中使用Union查询,并使用join,支持分页
$query1 = class1::find()->where($where);
$query2 = class1::find()->alias('a')->join('left join', class2::tablename() . 'as b', 'b.id = a.objid')->select('a.*')->where($where2);
$queryall = $query1->union($query2, true);
$query = (new query())->from(['c' => $queryall])->select('c.*,d.type,d.title')->join('left join', class3::tablename() . 'as d', 'd.id = c.objid')->distinct(true)->orderby(['c.time'=>sort_desc]);
$sql = $query->createcommand()->getrawsql();
$result = $query->offset(($page - 1) * 10)->limit(10)->all();
$totalcount = $query->count();
$pagination = new pagination(['totalcount'=>$totalcount, 'pagesize'=>10]);
$result = $query->offset($pagination->offset)->limit($pagination->limit)->all();
上一篇: 带女朋友去游泳的三个好处
下一篇: PHP RSA签名