简介

  • 多表查询会涉及到连接表,分为内连接,外连接(又细分为左连接、右连接)。

内连接

  • 语法:select * from table_a inner join table_b on table_a.id = table_b.id
  • 说明:检索结果是返回两个表id相交集的地方,相当与from table_a, table_b where...这样的where语句
  • 图示说明:
    mysql内连接与外连接

左连接

  • 语法:select * from table_a left join table_b on table_a.id = table_b.id
  • 说明:检索结果是左边的全部记录,以及符合条件的右表记录,记录不足的地方会使用null填充。
  • 图示说明:
    mysql内连接与外连接

右连接

  • 类似与左连接,以右边记录为基础。

结束

  • 外连接可以使用left outer join ... on ...,一般省略outer。
  • 内连接中inner join 与 单用join效果相同。

参考:https://blog.csdn.net/plg17/article/details/78758593

相关文章:

  • 2022-12-23
  • 2021-09-17
  • 2021-07-09
  • 2021-05-30
  • 2021-10-16
  • 2021-10-07
  • 2021-06-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2021-06-20
  • 2021-04-10
相关资源
相似解决方案