tp5 linked list query, find out the empty data in the left table

Background: tp5 A and B table join linked list query, find out the data in table A whose data in table B is empty and the data in table A whose data in table B is not empty

This operation will use EXP and IS NULL

Find out the data in Table A whose data in Table B is empty SQL

$where[] = ['exp',Db::raw("b.id IS NULL")];

$list = db('table1')->alias('a')
            ->join('table2 b', 'a.id = b.a_id', 'left')
            ->field('a.*,b.a_id')
            ->where($where)
            ->select();

Table B data is not empty A table data SQL

$where[] = ['exp',Db::raw("b.id IS NOT NULL")];

$list = db('table1')->alias('a')
            ->join('table2 b', 'a.id = b.a_id', 'left')
            ->field('a.*,b.a_id')
            ->where($where)
            ->select();

Guess you like

Origin blog.csdn.net/gjwgjw1111/article/details/131954643