回覆列表
  • 1 # Abnnjhg

    1,簡單子查詢;select name,age from person where age > ( select age from person where name = "孫權")2,in巢狀查詢;select name from person where countryid in ( select countryid from country where countryname = "魏國")3,some巢狀查詢select name from person where countryid = some       --用等號和以下查詢到的值比較,如果與其中一個相等,就返回( select countryid from country where countryname = "魏國")4,all巢狀查詢select name from person where countryid > all   --當countryid大於以下返回的所有id,此結果才為True,此結果才返回( select countryid from country where countryname = "魏國")5,exits巢狀查詢SELECT * FROM PersonWHERE exists( SELECT 1 --SELECT 0 SELECT NULL 返回結果都一樣,因為這三個子查詢都有結果集返回,因此總是True SELECT * FROM Person照常執行) 但是如果子查詢中因為加了條件而沒有結果集返回,則主語句就不執行了:SELECT * FROM PersonWHERE exists( SELECT * FROM Person WHERE Person_Id = 100 --如果不存在Person_Id的記錄,則子查詢沒有結果集返回,主語句不執行)

  • 中秋節和大豐收的關聯?
  • 特朗普為何突然訪問韓國?