Yii2 subquery in Active Record

Assuming that your models are named BaseTwitter and BaseFollower accordingly, this should work: $subQuery = BaseFollower::find()->select(‘id’); $query = BaseTwitter::find()->where([‘not in’, ‘id’, $subQuery]); $models = $query->all();