Oracle 第13章 當一個查詢依賴另一個查詢

來源:互聯網
上載者:User

標籤:

 進階子查詢   子查詢(subquery) 

知識點一:  多表串連之間的關係

例如 希望知道哪種種類的書籍已經借出去了。

select distinct c.parent_catagory, c.sub_category

from category c, bookshelf b, bookshelf_checkout bc

where c.category_name = b.category_name and b.title = bc.title

distinct 關鍵字 去重

此例中的3表關聯的 之間的關係:要串連3表必須把其中兩個表與第三個表串連起來。

 1.CATEGORY 表串連到 BOOKSHELF表, 它們串連的結果再與 BOOKSHELF_CHECKOUT表串連。  DISTINCT字句去重 

 注意:並不是每個表都與其它每個表相串連。表之間的串連通常比被串連的表的數量少1.

知識點二: 相互關聯的子查詢

a.where 子查詢      where字句 可以包含SELECT語句的子查詢, where 子查詢的子句where 還可以嵌套  

select distinct c.parent_categorty, c.sub_category

from categort c 

where category_name in 

  (select category_name from bookshelf

   where title in

     (select title from bookshelf_checkout) 

  );

這個查詢與知識點一中的查詢結果一樣

a: 子查詢可以引用在其主查詢中使用的表的列(即下例中 bookshelf 表中沒有title列)

  select title from bookshelf_author

  where title in

    (select title from bookshelf

    where author_name = ‘setphena hay gould’)

 

Oracle 第13章 當一個查詢依賴另一個查詢

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.