通俗易懂的join、left join、right join、full join、cross join
内连接:列出与连接条件匹配的数据行(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的更多相关文章
- T-SQL 中的CROSS JOIN用法(半翻译)
突然发现个很吊的链接,我们来看看学习数据库要做些什么,胆小慎点:DBA工作内容!!!! 今天来翻译一篇关于T-SQL的文章,本文可供微软认证70-461:QueryingMicrosoft SQL S ...
- MySQL应用之CROSS JOIN用法简介教程
目录 2. cross join用法 @ 本博客翻译自两篇博客的: http://www.mysqltutorial.org/mysql-cross-join/ https://www.w3resou ...
- 高级T-SQL进阶系列 (一)【上篇】:使用 CROSS JOIN 介绍高级T-SQL
[译注:此文为翻译,由于本人水平所限,疏漏在所难免,欢迎探讨指正] 原文连接:传送门 这是一个新进阶系列的第一篇文章,我们将浏览Transact-SQL(T-SQL)的更多高级特性.这个进阶系列将会包 ...
- Mysql常用sql语句(15)- cross join 交叉连接
测试必备的Mysql常用sql语句 https://www.cnblogs.com/poloyy/category/1683347.html 前言 交叉连接就是求多表之间的笛卡尔积 讲道理..这个我都 ...
- SQL中inner join、outer join和cross join的区别
对于SQL中inner join.outer join和cross join的区别简介:现有两张表,Table A 是左边的表.Table B 是右边的表.其各有四条记录,其中有两条记录name是相同 ...
- Cross join in excel --- Copy from Internet
Set up the Workbook In this example, there are two tables -- Raw Materials and Packaging -- and each ...
- CROSS JOIN连接用于生成两张表的笛卡尔集
将两张表的情况全部列举出来 结果表: 列= 原表列数相加 行= 原表行数相乘 CROSS JOIN连接用于生成两张表的笛卡尔集. 在sql中cross join的使用: 1.返回的记录数为两个 ...
- MySql的join(连接)查询 (三表 left join 写法)
1.内连接:将两个表中存在连结关系的字段符合连接条件的记录形成记录集 Select A.name,B.name from A inner join B on A.id=B.id和 Select A.n ...
- left join ,right join ,inner join ,cross join 区别
left join ,right join ,inner join ,cross join 区别(参考:http://zhidao.baidu.com/link?url=gpOl9HXZR0OrQuy ...
随机推荐
- 【POJ1573】Robot Motion
题目传送门 本题知识点:模拟 本题的题意也很简单. 给出一个矩阵,矩阵里面有着东南西北(上下左右)的指示,当机器人走到上面时则会按照指示前进.机器人每次都从最上面一行的某一列进入. 需要判断的是机器人 ...
- Tomcat启动时,控制台和IDEA控制台中文乱码解决方案
Tomcat启动时 控制台中文乱码 cmd控制台 IDEA控制台 解决方案 cmd乱码 打开Tomcat目录下的apache-tomcat-8.5.47\conf\logging.properties ...
- Amazon | OA 2019 | Optimal Utilization
Given 2 lists a and b. Each element is a pair of integers where the first integer represents the uni ...
- 通过sed -i ,通过准备好的sh脚本,来设置linux iptable白名单
通过准备好的sh脚本,来设置linux iptable白名单 特定字符串的行前插入新行 sed -i '/特定字符串/i 新行字符串' file #!/bin/bash del_stdin_buf() ...
- 泡泡一分钟:Tightly-Coupled Aided Inertial Navigation with Point and Plane Features
Tightly-Coupled Aided Inertial Navigation with Point and Plane Features 具有点和平面特征的紧密耦合辅助惯性导航 Yulin Ya ...
- Shell流程控制语句for
for语法格式: for 变量 in 参数列表 do 命令 done 或者 for 变量 in 参数列表 ; do 命令 done for语句流程控制图: 实例: [root@youxi1 ~]# v ...
- Shenzhen Wanze Technology Co., Ltd.技术支持
本网页为Shenzhen Wanze Technology Co., Ltd.团队的技术支持网址,如果在我们开发的游戏中遇到任何问题,欢迎联系我们! QQ:2535510006 邮箱:25355100 ...
- python之psutil模块
简述 psutil是一个跨平台库(http://code.google.com/p/psutil/) ,能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息.它主要应用于系 ...
- Spring MVC -- 表达式于语言(EL)
JSP 2.0最重要的特性之一就是表达式语言(EL),JSP用户可以用它来访问应用程序数据.由于受到ECMAScript和XPath表达式语言的启发,EL也设计成可以轻松地编写免脚本(就是不用在jsp ...
- [LeetCode] 162. Find Peak Element 查找峰值元素
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...