精品丰满熟女一区二区三区_五月天亚洲欧美综合网_亚洲青青青在线观看_国产一区二区精选

  • <menu id="29e66"></menu>

    <bdo id="29e66"><mark id="29e66"><legend id="29e66"></legend></mark></bdo>

  • <pre id="29e66"><tt id="29e66"><rt id="29e66"></rt></tt></pre>

      <label id="29e66"></label><address id="29e66"><mark id="29e66"><strike id="29e66"></strike></mark></address>
      學習啦>學習英語>專業(yè)英語>計算機英語>

      數(shù)據(jù)庫中exists語句的用法

      時間: 長思709 分享

        數(shù)據(jù)庫中exists語句的用法的用法你知道嗎?下面小編就跟你們詳細介紹下數(shù)據(jù)庫中exists語句的用法的用法,希望對你們有用。

        數(shù)據(jù)庫中exists語句的用法的用法如下:

        SQL中EXISTS的用法

        問題:查詢學過編號為"01"并且也學過編號為"02"的課程的同學的信息

        --方法1

        Sql代碼

        select Student.* from Student , SC where Student.S# = SC.S# and SC.C# = '01' and exists (Select 1 from SC SC_2 where SC_2.S# = SC.S# and SC_2.C# = '02') order by Student.S#

        EXISTS用于檢查子查詢是否至少會返回一行數(shù)據(jù),該子查詢實際上并不返回任何數(shù)據(jù),而是返回值True或False

        例表A:TableIn

        例表B:TableEx

        (二). 比較使用 EXISTS 和 IN 的查詢。注意兩個查詢返回相同的結(jié)果。

        select * from TableIn where exists(select BID from TableEx where BNAME=TableIn.ANAME)

        select * from TableIn where ANAME in(select BNAME from TableEx)

       ?。ㄈ? 比較使用 EXISTS 和 = ANY 的查詢。注意兩個查詢返回相同的結(jié)果。

        select * from TableIn where exists(select BID from TableEx where BNAME=TableIn.ANAME)

        select * from TableIn where ANAME=ANY(select BNAME from TableEx)

        NOT EXISTS 的作用與 EXISTS 正好相反。如果子查詢沒有返回行,則滿足了 NOT EXISTS 中的 WHERE 子句。

        一種通俗的可以理解為:將外查詢表的每一行,代入內(nèi)查詢作為檢驗,如果內(nèi)查詢返回的結(jié)果取非空值,則EXISTS子句返回TRUE,這一行行可作為外查詢的結(jié)果行,否則不能作為結(jié)果。

        EXISTS與IN的使用效率的問題,通常情況下采用exists要比in效率高,因為IN不走索引,但要看實際情況具體使用:

        IN適合于外表大而內(nèi)表小的情況;EXISTS適合于外表小而內(nèi)表大的情況。

      數(shù)據(jù)庫中exists語句的用法

      數(shù)據(jù)庫中exists語句的用法的用法你知道嗎?下面小編就跟你們詳細介紹下數(shù)據(jù)庫中exists語句的用法的用法,希望對你們有用。 數(shù)據(jù)庫中exists語句的用法的用法如下: SQL中EXISTS的用法 問題:查詢學過編號為01并且也學過編號為02的課程的
      推薦度:
      點擊下載文檔文檔為doc格式
      543180