mysql-关联查询

连接查询

  • 内连接:取交集,即两个表中都存在的数据
    • select * from 表名1 inner join 表名2 on 表1.列= 表2.列;
  • 左连接:取左表中特有的数据,对于右表中不存在的数据使用null填充
    • select * from 表名1 left join 表名2 on 表1.列= 表2.列;
  • 右连接:取右表中特有的数据,对于左表中不存在的数据使用null填充
    • select * from 表名1 right join 表名2 on 表1.列= 表2.列;

自关联
通过自关联进行查询时,当前关联的表中一定会存在两个相关联的字段

  • 自关联要用别名
  • select * from 表名 as 别名1 inner join 表名 as 别名2 on 别名1.列=别名2.列
posted @ 2022-05-07 18:30  喝娃哈哈的水中鱼  阅读(162)  评论(0)    收藏  举报