thinkphp5 使用 join

alias相当于重命名

如果thinkphp5里想要使用join操作的话

$re = Db::table('meeting')
            ->alias('m')
            ->join('meeting_major b','m.id = b.meeting_id')
            ->where([
                'b.major' => $real_major,
                'b.year' => $now_year,
                'm.state' => ['<',2]
            ])
            ->select();

如果想要多个条件连接的话

$re = Db::table('meeting')
            ->alias('m')
            ->join('meeting_major b','m.id = b.meeting_id and xxxxxxxxxxx')
            ->where([
                'b.major' => $real_major,
                'b.year' => $now_year,
                'm.state' => ['<',2]
            ])
            ->select();

 

你可能感兴趣的:(后台开发,ThinkPHP5.0,开发日记)