oracle 4 : 串連查詢

來源:互聯網
上載者:User

標籤:and   rac   層級   沒有   串連   mgr   nat   src   多個   

串連查詢: join

(1)等值串連: 通常用主外鍵串連

(2)非等值串連

     例

--統計每個人姓名。部門名,薪資,薪資層級select ename,d.dname,e.sal,s.gradefrom emp e,dept d,salgrade swhere e.sal between s.losal and s.hisaland e.deptno = d.deptno

(3)內部串連 關鍵字 inner join on 想當於where

select *from emp einner join dept don d.deptno = e.deptno

(4)外部串連   左右連

  左串連:left join 以左邊表為主表

    右串連:

  全外串連 :把表中所有資料都顯示出來,有關聯的資料,使用關聯條件拼接,沒有資料的用null 填充  關鍵字: full outer join

(5)自身串連

  

--自身串連  查詢員工的上級領導select e1.ename,e1.job,e2.ename from emp e1,emp e2where e1.mgr = e2.empno

(6)交叉串連,產生笛卡爾積

  

--交叉串連select * from emp cross join dept

(6)自然串連  關鍵字 natural join

  根據同名列進行自動連接

  要求同名列的資料類型必須相同,長度必須相同,主外鍵必須一致

  相當於沒有條件的等值串連

--自然串連select * from emp natural join dept

(7)聯集查詢: 多個投影結果合并在一起  關鍵字 union all

  要求進行查詢的結果的列數必須相同:

  對應的列的資料類型必須相同,長度口蹄疫不同

  union all 全部顯示

  union 自動去除重複資料  

  

--聯集查詢select empno, enamefrom empunion allselect deptno,dname from dept

 

去重關鍵字: distinct:

--查詢都有哪些部門有員工,員工在哪些部門裡select distinct deptno from emp

 

 

 

 

 

 

 

 

 

oracle 4 : 串連查詢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.