thinkphp 中一个语法问题 select * from A where roomid in(select roomid from B where accontid=1000)

2025-04-27 04:12:42
推荐回答(1个)
回答1:

从3.0版本开始新增了子查询支持,有两种使用方式:

  1. 使用select方法 当select方法的参数为false的时候,表示不进行查询只是返回构建SQL

    $subQuery = $model->field('roomid')->table('tablename')->where(array('accontid' => 1000))->select(false); 

  2. 使用buildSql方法

    $subQuery = $model->field('roomid')->table('tablename')->where(array('accontid' => 1000))->buildSql(); 

  3. 利用子查询进行查询

    $model->table($subQuery.' a')->where()->order()->select()