嵌套查詢

(1)簡單子查詢
示例:

select name,age from person 
where age > 
    (
        select age from person 
        where name = '孫權'
    )

(2)in嵌套查詢
  in關鍵字用於where子句中用來判斷查詢的表達式是否在多個值的列表中。返回滿足in列表中的滿足條件的記錄。
示例:

select name from person 
where countryid in 
(
select countryid from country
where countryname = '魏國'
)

(3)some嵌套查詢
  some在sql中的邏輯運算符號,如果在一系列比較中,有些值爲True,那麼結果就爲True。some的語法是:
示例:

select name from person 
where countryid = some   
(
select countryid from country
where countryname = '魏國'
)

(4)all嵌套查詢
  all是sql中的邏輯運算符好,如果一系列的比較都爲true,那麼結果才能爲true。
示例:

select name from person 
where countryid > all
(
select countryid from country
where countryname = '魏國'
)

(5)exists嵌套查詢
  exists是sql中的邏輯運算符號。如果子查詢有結果集返回,那麼就爲True。exists代表“存在”的意義,它只查找滿足條件的那些記錄。一旦找到第一個匹配的記錄後,就馬上停止查找。
exists 子查詢
  其中子查詢是一個首先的select語句,不允許有compute子句和into關鍵字。
exists 的意思是,子查詢是否有結果集返回。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章