我想以以下方式实现sql查询:
INNER JOIN
`Product_has_ProductFeature` t ON `Product`.`id` = t.`productId` AND t.`productFeatureValueId` = 1
INNER JOIN
`Product_has_ProductFeature` t1 ON `Product`.`id` = t1.`productId` AND t1.`productFeatureValueId` = 5
我该如何使用innerJoin()
或上面提到的方法来做到这一点?
innerJoin()
是一个方法从查询类。
您可以尝试这样的事情。
$query = new \yii\db\Query;
$command = $query->innerJoin(
'Product_has_ProductFeature',
`Product`.`id` = t.`productId`)
->andWhere('t.`productFeatureValueId` = 1')
->createCommand();
$queryResult = $command->query();