朱纯树博客
VPS测评推荐网站
cloudacead cloudacead

[记录]TP5多表联查join参数详解

需求:多表联查时 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参数详解

赞(0) 打赏
未经允许不得转载:VPS测评推荐网站 - 朱纯树博客 » [记录]TP5多表联查join参数详解

评论 3

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #0

    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.

  2. #0

    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

  3. #0

    Mymusicmp3 : http://huiruite.com/

    东南亚小野猫1年前 (2022-01-07)回复