thinkphp 多表查询

我将不同的表名存在了一个数据表,这些表名对应的数据表的列都是一致的,现在的要求是,把这些表里面的数据按照筛选条件筛出来。

$list = Db::table("v_software_list")->where('delete', 1)->field('field_js')->select();
$select = '';
foreach ($list as $key => $val) {
    if ($key == 0) {
        $sqlField = $val['field_js'];
        $select = Db::table($sqlField)->comment($sqlField)->field('id,content,title,states,create_time,update_time,desc,delete,sql');
    } elseif($key == count($list) - 1) {
        $sqlField = $val['field_js'];
        $sql = Db::table($sqlField)->comment($sqlField)->field('id,content,title,states,create_time,update_time,desc,delete,sql')->where(handle($data))->buildSql();
        $select = $select->union([$sql])->buildSql();
    } else {
        $sqlField = $val['field_js'];
        $sql = Db::table($sqlField)->comment($sqlField)->field('id,content,title,states,create_time,update_time,desc,delete,sql')->where(handle($data))->buildSql();
        $select = $select->union([$sql]);
    }

}
$getlist = Db::table($select." a")->select();

不知道这样的运行速度怎么样,暂时只能这样了…

thinkphp 多表查询插图

没有账号? 忘记密码?

社交账号快速登录