本文介绍了Yii2 innerJoin()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过以下方式实现sql查询:
I want to implement a sql query in the following way:
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()
或上面提到的类似方法来做到这一点?
How can I do this using innerJoin()
or something like above mentioned?
推荐答案
您可以尝试这样的事情.
You can try something like this.
$query = new \yii\db\Query;
$command = $query->innerJoin(
'Product_has_ProductFeature',
`Product`.`id` = t.`productId`)
->andWhere('t.`productFeatureValueId` = 1')
->createCommand();
$queryResult = $command->query();
这篇关于Yii2 innerJoin()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!