oracle 之 连接查询

where 连接

select * from a,b //使用的是笛卡尔乘积  显示 a.count*b.count 条数

select * from a,b where a.id=b.id 其实只是显示的隐藏了笛卡尔乘积,但是乘积并没有消失 且where 关联与 inner join 效果是一致的,都是取的并集,也就是双方都存在的id

left join on 连接

select * from a left join b on a.id=b.id  where  条件  //左连查询,以左为主,例如 a.id=1一条,b.id=1两条数据,那么就显示两条,b.id不存在 a.id的,那么后续b表列为空,where 条件会影响数据条数

同理:right join on 连接 

natural join  连接

select  * from a natural join b   //差不多和where, inner join 一致,但是之显示 a或b的id 之中一个,另一个消失

cross join 连接

select  * from a  cross join b    //与select * from a,b 是一致的

join  using    连接

select *from a join b using(a.id) //与natural join 结果一致

join  using    连接

select  * from a  join b on(a.id=b.id)   // 与inner join on 结果一致

full outer join on 连接

select * from a full outer join b on a.id=b.id  // 在原来inner jion 的基础上 显示出 a.id有的值,但是b表没有值

注意点:表之间的关联会影响到查询速度,一般oracle 的 查询量在亿级,超过这个很容易卡死掉

原文地址:https://www.cnblogs.com/zmztya/p/7205454.html