需求:多表联查时 a表id = b表id, a表id = c表id 但c表有的id是空的 就会导致查询出的结果不完整
join通常有下面几种类型,不同类型的join操作会影响返回的数据结果。
参数详解:
INNER: 等同于 JOIN(默认的JOIN类型),如果表中有至少一个匹配,则返回行
LEFT: 即使右表中没有匹配,也从左表返回所有的行
RIGHT: 即使左表中没有匹配,也从右表返回所有的行
FUL: 只要其中一个表中存在匹配,就返回行
写法1:[ '完整表名或者子查询'=>'别名' ] 写法2:'完整表名 别名' 写法3:'不带数据表前缀的表名'
join函数第三个参数类型
关联类型。可以为:INNER、LEFT、RIGHT、FULL,不区分大小写,默认为INNER
举例:
按照文章开头说的需求, 这样就可以查出我们需要的完整的数据
Db::table('aaaaa') ->alias('a') ->join('bbbbb b','a.id = b.id') ->join('ccccc c','a.id = c.id','LEFT') ->select();
-End-
文章来源于互联网:[记录]TP5多表联查join参数详解
Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do it! Your writing style has been amazed me. Thanks, very nice post.
I believe that is one of the such a lot vital info for me. And i’m happy studying your article. But should observation on few normal things, The website style is perfect, the articles is actually excellent : D. Excellent task, cheers
Mymusicmp3 : http://huiruite.com/