数据库 - SQL语句 - 跨表链接/多表链接的查询

目的:  两张表中数据联系起来查询符合条件的数据(笛卡尔积)

实现:SQL语句

(1)内连接:join xxx on xxx
    1 等值连接
        select 
              xxx 
        from  
            table1 
        (inner:表示内连接,可省略)join 
            table2 
        on
            xxx=xxx (链接条件)
        where(数据过滤)
            xxx=xxx ;
    2 非等值链接
        select 
              xxx 
        from  
            table1 
        (inner:表示内连接,可省略)join 
            table2 
        on
            (链接条件)变为:xxx between xxx and xxx
        where(数据过滤)
            xxx=xxx ;
    3 自链接
2)外连接:
    特点:一条一条匹配链接时,自动填充null匹配链接的表中没有的数据;与内连接相比查询记录条数多;
   1 左外链接
将join左边的表中的数据全部找出来
select .. from ... left (outer:可省略) join ... on ... where ...
2 右外链接
将join左边的表中的数据全部找出来
select .. from ... right (outer) join ... on ... where ...

 

posted @ 2020-04-24 20:36  丨Kouch  阅读(1309)  评论(0编辑  收藏  举报