thinkphp 多表查询和内连接查询的一些记录

            $model = new Model();
            $list = $model->table('l_project p,l_project_user pu')->where('pu.user_id = '.$_SESSION['id'].' AND p.team_id = '.$_SESSION['team_id'].' AND pu.project_id = p.id')->field('p.name,p.id,p.description')->select();
            $this->assign('list',$list);

            $team_user_list = M('TeamUser')->where('team_id = '.$_SESSION['team_id'])->field('id,user_id')->select();
            $model = new model();
            $sql = 'SELECT tu.user_id,tu.id,u.nickname FROM l_team_user AS tu INNER JOIN l_user AS u ON u.id = tu.user_id WHERE tu.user_id != '.$_SESSION['id'].' AND tu.team_id = '.$_SESSION['team_id'];
            $team_user_list = $model->query($sql);
            $this->assign('team_user_list',$team_user_list);


1、第一个是多表查询

2、第二个是内连接查询

你可能感兴趣的:(thinkphp 多表查询和内连接查询的一些记录)