内连接:列出与连接条件匹配的数据行(join\inner join)

外连接:两表合并,如有不相同的列,另外一个表显示null(left join\right join\full outer join\cross join)

以学生表:#table1和课程表:#table2为例

            

select * from #table1 stu join #table2 cou on stu.student_id = cou.stu_id;

Join

Inner join 等于join(当条件都满足时,列出满足条件的项)

执行结果和用where相同()

select * from #table1 stu left join #table2 cou on stu.student_id = cou.stu_id;

Left Join

left join :以左表为主,右表没有的项显示null;

select * from #table1 stu right join #table2 cou on stu.student_id = cou.stu_id;

Right Join

right join:以右表为主,左表没有的项显示null;

select * from #table1 stu full outer join #table2 cou on stu.student_id = cou.stu_id;

Full Outer Join

full outer join : 没有主次表之分,显示所有,相当于左、右连接的组合;

在Sql server数据库中,full join 和 full outer join(其他数据库没试过)

select * from #table1 stu full join #table2 cou on stu.student_id = cou.stu_id; ——结果和full outer join 一样;

select * from #table1 cross join #table2 ;

Cross Join

cross join(交叉连接\笛卡儿积):返回左表中的所有行,左表中的每一行与右表中的所有行组合;

     

通俗易懂的join、left join、right join、full join、cross join的更多相关文章

  1. T-SQL 中的CROSS JOIN用法(半翻译)

    突然发现个很吊的链接,我们来看看学习数据库要做些什么,胆小慎点:DBA工作内容!!!! 今天来翻译一篇关于T-SQL的文章,本文可供微软认证70-461:QueryingMicrosoft SQL S ...

  2. MySQL应用之CROSS JOIN用法简介教程

    目录 2. cross join用法 @ 本博客翻译自两篇博客的: http://www.mysqltutorial.org/mysql-cross-join/ https://www.w3resou ...

  3. 高级T-SQL进阶系列 (一)【上篇】:使用 CROSS JOIN 介绍高级T-SQL

    [译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文连接:传送门 这是一个新进阶系列的第一篇文章,我们将浏览Transact-SQL(T-SQL)的更多高级特性.这个进阶系列将会包 ...

  4. Mysql常用sql语句(15)- cross join 交叉连接

    测试必备的Mysql常用sql语句 https://www.cnblogs.com/poloyy/category/1683347.html 前言 交叉连接就是求多表之间的笛卡尔积 讲道理..这个我都 ...

  5. SQL中inner join、outer join和cross join的区别

    对于SQL中inner join.outer join和cross join的区别简介:现有两张表,Table A 是左边的表.Table B 是右边的表.其各有四条记录,其中有两条记录name是相同 ...

  6. Cross join in excel --- Copy from Internet

    Set up the Workbook In this example, there are two tables -- Raw Materials and Packaging -- and each ...

  7. CROSS JOIN连接用于生成两张表的笛卡尔集

    将两张表的情况全部列举出来 结果表: 列= 原表列数相加 行= 原表行数相乘     CROSS JOIN连接用于生成两张表的笛卡尔集. 在sql中cross join的使用: 1.返回的记录数为两个 ...

  8. MySql的join(连接)查询 (三表 left join 写法)

    1.内连接:将两个表中存在连结关系的字段符合连接条件的记录形成记录集 Select A.name,B.name from A inner join B on A.id=B.id和 Select A.n ...

  9. left join ,right join ,inner join ,cross join 区别

    left join ,right join ,inner join ,cross join 区别(参考:http://zhidao.baidu.com/link?url=gpOl9HXZR0OrQuy ...

随机推荐

  1. OpenFOAM——90度T型管

    本算例来自<ANSYS Fluid Dynamics Verification Manual>中的VMFL010: Laminar Flow in a 90° Tee-Junction. ...

  2. Django入门——《Python编程从入门到实践》

    Django是一个Web框架--一套用于帮助开发交互式网站的工具.Django能够响应网页请求,还能让你更轻松地读写数据库.管理用户等. 1.建立项目 开始编写一个名为"学习笔记" ...

  3. html5 css3 背景视频循环播放代码

    <div style ="position: absolute; z-index: -1; top: 0px; left: 0px; bottom: 0px; right: 0px; ...

  4. Java8新特性 (一)Lambda

    目录 一.Lambda介绍 二.Lambda用法实例 三.Lambda变量作用域 前言: 这两天彻底的复习了一遍Java8的各种新特性,趁着热乎劲,把知识点整理成博客的形式保存一下. 一.Lambda ...

  5. golang调用 exec命令 出现too many open files

    systemd 启动的服务, 跟系统的ulimit 没有关系. 大概的意思就是通过systemd启动的服务,不会使用ulimit中的配置,需要在systemd中或者service配置文件中定义,可以通 ...

  6. Bi-Directional ConvLSTM U-Net with Densley Connected Convolutions

    Bi-Directional ConvLSTM U-Net with Densley Connected Convolutions  ICCV workshop 2019  2019-09-15 11 ...

  7. 这42个Python小例子,太走心

    告别枯燥,60秒学会一个Python小例子.奔着此出发点,我在过去1个月,将平时经常使用的代码段换为小例子,分享出来后受到大家的喜欢. 一.基本操作 1 链式比较 i = 3print(1 <  ...

  8. excel VBA 密码设置问题

    Excel中VBA设置密码的步骤如下: 1.右键点击任何工作表,选择VBAProject属性: 2.在新对话框总,选择“保护”选项卡: 3.勾选查看时锁定,输入密码即可.  

  9. [LeetCode]577. Employee Bonus 员工奖金

    Select all employee's name and bonus whose bonus is < 1000. Table:Employee +-------+--------+---- ...

  10. 【视频开发】【计算机视觉】doppia编译之四:安装其他库、编译和运行doppia

    (与本节内容无关///////////////////////////保存图片参数为--gui.save_all_screenshots true////////////////////)  在我们安 ...