oracle 之 連線查詢

2022-06-10 15:09:09 字數 952 閱讀 9744

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 的 查詢量在億級,超過這個很容易卡死掉

oracle高階查詢之連線查詢 集合運算

一 集合運算 minus補集,返回第乙個查詢結果的記錄減去第二個查詢結果的記錄後剩下的記錄 select deptno from dept minus select deptno from emp intersect交集,返回兩個查詢共有的記錄 select deptno from dept int...

oracle查詢連線

select from emp select from dept 左連線 1 查詢與左邊表dept 4 相關聯的資料,如deptno 40在右邊沒有對應的資料,則顯示為空 select from dept left join emp on dept.deptno emp.deptno 查詢與左邊表相...

Oracle連線查詢

1 內連線 select e.d.dname from emp e,dept d where e.deptno d.deptno 隱式內連線查詢實際的語句可以為 select e.d.dname from emp e inner join dept d on d.deptno e.deptno 2 ...