内连接与外连接

上一篇 / 下一篇  2015-03-06 10:00:37 / 个人分类:数据库

1.内连接(自然连接):
* 概念: 只有两个表相匹配的行才能在结果集中出现
* join 或inner join
* 语句:select * from table1 join table2 on table1.id=table2.id
2、外连接
1)左外连接
* 连接时左边的表不加限制,如果左表的某行在右表中没有匹配行,则在相关联的结果集行中右表的所有选择列表列均为空值(null)。
* left join 或者 left outer join
* select * from table1 left join table2 on table1.id=table2.id
2)右外连接
* 连接时右边的表不加限制,如果右表的某行在左表中没有匹配行,则在相关联的结果集行中左表的所有选择列表列均为空值(null)。
* right join 或者 right outer join
* select * from table1 right join table2 on table1.id=table2.id
3)全外连接
* 连接时左右边表都不加限制
* full join 或者 full outer join
* select * from table1 full join table2 on table1.id=table2.id

3.交叉连接
*没有where的交叉语句,连接的结果数为表1的数量*表2的数量
* cross join 
* select * from table1  cross join  table2



TAG:

 

评分:0

我来说两句

Open Toolbar