zoukankan      html  css  js  c++  java
  • TSQL之JOIN(连接)彻底理解

    T-SQL之JOIN彻底理解

    本文不解释,欢迎提问解答,谢谢。直接上代码:

    --测试数据建立
    Create TABLE JOIN_TEST(
    COLA INT,
    COLB INT
    )
     
    GO
    INSERT INTO JOIN_TEST
    SELECT 1,1
     
    INSERT INTO JOIN_TEST
    SELECT 1,1
     
    GO
    --测试数据建立完毕
     
    SELECT * FROM JOIN_TEST
    /*
     
    COLA        COLB
    ----------- -----------
    1           1
    1           1
     
    (2 行受影响)
    */
     
     
    SELECT * FROM JOIN_TEST A  CROSS JOIN JOIN_TEST B
    /*
    COLA        COLB        COLA        COLB
    ----------- ----------- ----------- -----------
    1           1           1           1
    1           1           1           1
    1           1           1           1
    1           1           1           1
     
    (4 行受影响)
     
    */
     
     
    SELECT * FROM JOIN_TEST A  INNER JOIN  JOIN_TEST B ON A.COLA=B.COLA
    /*
    COLA        COLB        COLA        COLB
    ----------- ----------- ----------- -----------
    1           1           1           1
    1           1           1           1
    1           1           1           1
    1           1           1           1
    (4 行受影响)
     
    */
     
     
    SELECT * FROM JOIN_TEST A  LEFT JOIN  JOIN_TEST B ON A.COLA=B.COLA
    /*
    COLA        COLB        COLA        COLB
    ----------- ----------- ----------- -----------
    1           1           1           1
    1           1           1           1
    1           1           1           1
    1           1           1           1
    (4 行受影响)
     
    */
     
    SELECT * FROM JOIN_TEST A  LEFT JOIN  JOIN_TEST B ON A.COLA=B.COLA AND A.COLA<>1
    /*
    COLA        COLB        COLA        COLB
    ----------- ----------- ----------- -----------
    1           1           NULL        NULL
    1           1           NULL        NULL
    (2 行受影响)
    */
     
    SELECT * FROM JOIN_TEST A  LEFT JOIN  JOIN_TEST B ON A.COLA=B.COLA WHERE A.COLA<>1
    /*
    COLA        COLB        COLA        COLB
    ----------- ----------- ----------- -----------
     
    (0 行受影响)
    */
     
    SELECT * FROM JOIN_TEST A  FULL JOIN  JOIN_TEST B ON A.COLA=B.COLA AND A.COLA<>1
    /*
    COLA        COLB        COLA        COLB
    ----------- ----------- ----------- -----------
    1           1           NULL        NULL
    1           1           NULL        NULL
    NULL        NULL        1           1
    NULL        NULL        1           1
    */
     
    SELECT * FROM JOIN_TEST A  FULL JOIN  JOIN_TEST B ON A.COLA=B.COLA where A.COLA<>1
    /*
    COLA        COLB        COLA        COLB
    ----------- ----------- ----------- -----------
     
    (0 行受影响)
    */
  • 相关阅读:
    codeforces #313(div 2)
    云计算设计模式(二十四)——仆人键模式
    封装一个ViewPager真正的实现图片无限循环滚动带导航点
    HDU4622:Reincarnation(后缀数组,求区间内不同子串的个数)
    数据库分页
    [Swift]LeetCode728. 自除数 | Self Dividing Numbers
    [Swift]LeetCode726. 原子的数量 | Number of Atoms
    [Swift]LeetCode725. 分隔链表 | Split Linked List in Parts
    [Swift]LeetCode724. 寻找数组的中心索引 | Find Pivot Index
    [Swift]LeetCode722. 删除注释 | Remove Comments
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2478551.html
Copyright © 2011-2022 走看看