Yii2innerJoin() [英] Yii2 innerJoin()

查看:19
本文介绍了Yii2innerJoin()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过以下方式实现一个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?

推荐答案

innerJoin() 是一个 方法 来自 查询 类.

innerJoin() is a method from the Query class.

你可以试试这样的.

$query = new yiidbQuery;
$command = $query->innerJoin(
         'Product_has_ProductFeature',
         `Product`.`id` = t.`productId`)
     ->andWhere('t.`productFeatureValueId` = 1')
     ->createCommand();
$queryResult = $command->query();

这篇关于Yii2innerJoin()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆