我正在尝试获取与 IN 子句中的所有值相匹配的查询。这就是我现在在 UsersSearch.php 模型中所拥有的:
$categoryIdsMatching = UsersCategoriesAssn::find()
->select('userID')
->distinct(true)
->joinWith('userCategory')
->andWhere(['IN', 'usersCategories.id', $this->catNameSearch])
->column();
$query->andWhere(['userID'=>$categoryIdsMatching]);
但它获取的记录至少匹配其中一个值...我如何设置 andWhere 子句来匹配所有值而不是其中一些值?
最佳答案
这可能类似于:
$categoryIdsMatching = UsersCategoriesAssn::find()
->select('userID')
->distinct(true)
->joinWith('userCategory')
->andWhere(['IN', 'usersCategories.id', $this->catNameSearch])
->groupBy('userTable.userID')
->having('COUNT(userTable.userID) ='.count($this->catNameSearch));
可能没有其他方法可以过滤 IN 运算符来匹配 MySQL 中的所有值。
关于mysql - Yii2 匹配 IN 子句中的所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35797949/