首页 > 开发 > MySQL > 正文

yii2 多表联查 where条件里 A表字段=B表字段怎么表示

2017-09-08 08:58:37  来源:网友分享

yii2 多表联查 where条件里 A表字段=B表字段怎么表示?

    $res =self::find()->select(['a.id','a.name'])    ->join('LEFT JOIN','b','b.qid=a.id')    ->join('LEFT JOIN','c','c.uid=b.uid')    ->where(['a.state'=>0,'b.state'=>0,'c.state'=>0,'c.uid'=>123456])    ->asArray()->all();    

想在where条件里加上c.type=b.type怎么加???

解决方案

$query->andWhere(new \yii\db\Expression('c.type = b.type'))