php - 根据子表中的字段值从数据库中选择行

标签 php mysql database yii

我想根据另一个表中的某些值从表中选择一些行。我有这个代码:

$row = Yii::app()->cre->createCommand()
    ->from('test')
    ->queryAll();

我应该为此写入什么 where() 子句? 解释: 我有表 test 和相关的 test2,其中有 test_id 字段和 compare_id 字段。我需要从 test 获取所有行,其中 compare_id = 1

最佳答案

我认为它应该与连接一起使用:

$row = Yii::app()->cre->createCommand()
    ->from('test')
    ->join('test2','test2.compare_id = test.test_id')
    ->queryAll();

关于php - 根据子表中的字段值从数据库中选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26507004/

相关文章:

php - 如何将动态构造的 ext/mysql 查询转换为 PDO 准备语句?

php - mysql 表连接和使用 DISTINCT

php - PHP 比较中的变量位置

php - 如何将 sql 输出显示到 php 中?

PHP strtotime() 对于 JavaScript 日期字符串返回 false

mysql 语句 WHERE 未知

php - 根据记录类型计算总和

PHP5数据库密码能被盗吗?

mysql - 数据库设计 : User Profiles like in Meetup. com

android - ListView 的这个自定义 CursorAdapter 是否为 Android 正确编码?