您的位置:首页 > 数据库 > Oracle

oracle中left join,right join,inner join用法

2014-08-09 11:15 225 查看

一、oracle中left join和right join的区别

通俗的讲:


A left join
B 的连接的记录数与A表的记录数同


A right join
B 的连接的记录数与B表的记录数同


A left join
B 等价B right join A
二、内连接

1.概念:内联接是用比较运算符比较要联接列的值的联接

2.内连接:join 或 inner join

3.sql语句

select * from table1 join table2 on table1.id=table2.id

4.等价

a:select a.*,b.* from table1 a,table2 b where a.id=b.id

b:select * from table1 cross join table2 where table1.id=table2.id (注:cross join后加条件只能用where,不能用on)

三、交叉连接(完全)

1.概念:没有 where 子句的交叉联接将产生联接所涉及的表的笛卡尔积。第一个表的行数乘以第二个表的行数等于笛卡尔积结果集的大小。

2.交叉连接:cross join (不带条件where...)

3.sql语句

select * from table1 cross join table2

注释:返回3*3=9条记录,即笛卡尔积

4.等价

a:select * from table1,table2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: