语法
join ( mixed join [, mixed $condition = null [, string $type = ‘INNER‘]] )
示例
别名
Db::table(‘think_artist‘) ->alias(‘a‘) ->join(‘think_work w‘,‘a.id = w.artist_id‘) ->join(‘think_card c‘,‘a.card_id = c.id‘) ->select();
Db::table(‘think_artist‘) ->alias(‘a‘) ->join(‘__WORK__ w‘,‘a.id = w.artist_id‘) ->join(‘__CARD__ c‘,‘a.card_id = c.id‘) ->select();
$join = [ [‘think_work w‘,‘a.id=w.artist_id‘], [‘think_card c‘,‘a.card_id=c.id‘], ];Db::table(‘think_user‘)->alias(‘a‘)->join($join)->select();
全称
Db::table(‘think_user‘)->join(‘__WORK__‘,‘__ARTIST__.id = __WORK__.artist_id‘)->select();
right方式
Db::table(‘think_user‘)->alias(‘a‘)->join(‘word w‘,‘a.id = w.artist_id‘,‘RIGHT‘)->select();
表名是子查询
$subsql = Db::table(‘think_work‘) ->where([‘status‘=>1]) ->field(‘artist_id,count(id) count‘) ->group(‘artist_id‘) ->buildSql(); Db::table(‘think_user‘) ->alias(‘a‘) ->join([$subsql=> ‘w‘], ‘a.artist_id = w.artist_id‘) ->select();
时间: 2024-10-25 08:50:24