yii2 left join 查询


SpellTeamLine::find()->select('a.*,b.order_sn,b.member_id')->alias('a')->joinWith(['spellTeamSub b'],false)->where(['spell_team_id'=>$id])->orderBy('id desc')->asArray()->all();

手册:
* Order::find()->joinWith('books', true, 'INNER JOIN')->all();
* // find all orders, eager loading "books", and sort the orders and books by the book names.
* Order::find()->joinWith([
* 'books' => function (\yii\db\ActiveQuery $query) {
* $query->orderBy('item.name');
* }
* ])->all();
* // find all orders that contain books of the category 'Science fiction', using the alias "b" for the books table
* Order::find()->joinWith(['books b'], true, 'INNER JOIN')->where(['b.category' => 'Science fiction'])->all();
* ```
*

猜你喜欢

转载自www.cnblogs.com/shaoyang0123/p/12966511.html
今日推荐