zoukankan      html  css  js  c++  java
  • 连表查询总结20140903

    结论:

    1、 左连表查询:循环匹配的数据加入到结果,然后将左表没有匹配的数据加入到结果

    2、 右连表查询:循环匹配的数据加入到结果,然后将右表没有匹配的数据加入到结果

    3、 完全连表查询:循环匹配的数据加入到结果,然后将两个表没有匹配的数据加入到结果

    1、 准备工作,两张表idtable 和 nametable,如图

    idtable 表: nametable表:

    clip_image002 clip_image004

    2、左连表查询,使用的是“left”,将“join”右边的表的连表条件的值循环和左表中匹配,匹配一次,则加入查询结果记录中,这个示范是,将nametable中value的四个值“1,1,2,6”,分别到idtable中去比对,结果记录了3条结果,然后将左表中剩余没有被匹配过的数据也加入到结果中,对应的右表字段为null;

    select a.*,b.* from dbo.idtable a left join dbo.nametable b on a.value=b.value

    clip_image006

    3、右连表查询,和左连表查询类似,只是这次是用左表的数据去匹配右表,然后将右表中剩余没有匹配的加入到结果中,对应的左表字段为null;

    select a.*,b.* from dbo.idtable a right join dbo.nametable b on a.value=b.value

    clip_image008

    4、完全连表查询,则是匹配完后,将两个表中剩余的没有匹配的都加入到结果中

    select a.*,b.* from dbo.idtable a full join dbo.nametable b on a.value=b.value

    clip_image010

  • 相关阅读:
    自编游戏
    宣言
    Leetcode: 12. Integer to Roman
    Leetcode: 11. Container With Most Water
    Leetcode: 10. Regular Expression Matching
    网络编程:listen函数
    网络编程:connect函数
    Leetcode: 9. Palindrome Number
    Leetcode: 8. String to Integer (atoi)
    Leetcode: 7. Reverse Integer
  • 原文地址:https://www.cnblogs.com/heiyexiaoguai/p/4822763.html
Copyright © 2011-2022 走看看