聯(lián)合查詢 使用方法

            聯(lián)合查詢

          Ø  Union :集合的并,不包括重復(fù)行

          select field1, field2, . field_n from tables UNION select field1, field2, . field_n from tables;

          Ø  union all:集合的并,包括重復(fù)行

          select field1, field2, .field_n from tables UNION ALL  select field1, field2, field_n from tables;

          Ø  intersect :集合的交,不包括重復(fù)行

          select field1, field2, field_n from tables INTERSECT select field1, field2, field_n from tables;

          Ø  minus:集合的差,不包括重復(fù)行

          select field1, field2, field_n from tables MINUS select field1, field2, field_n from tables;

           

          實(shí)例:


          Id
           Name
           score
           
          1
           Aaron
           78
           
          2
           Bill
           76
           
          3
           Cindy
           89
           
          4
           Damon
           90
           
          5
           Ella
           73
           
          6
           Frado
           61
           
          7
           Gill
           99
           
          8
           Hellen
           56
           
          9
           Ivan
           93
           
          10
           Jay
           90
           


          select * from student where id < 4 union select * from student where id > 2 and id < 6 的查詢結(jié)果:

          Id
           Name
           score
           
          1
           Aaron
           78
           
          2
           Bill
           76
           
          3
           Cindy
           89
           
          4
           Damon
           90
           
          5
           Ella
           73
           


          select * from student where id < 4 union All select * from student where id > 2 and id < 6的查詢結(jié)果:

          Id
           Name
           score
           
          1
           Aaron
           78
           
          2
           Bill
           76
           
          3
           Cindy
           89
           
          3
           Cindy
           89
           
          4
           Damon
           90
           
          5
           Ella
           73
           


          select * from student where id < 4 intersect select * from student where id > 2 and id < 6的查詢結(jié)果:

          Id
           Name
           score
           
          3
           Cindy
           89
           


          select * from student where id < 4 minus select * from student where id > 2 and id < 6的查詢結(jié)果:

          Id
           Name
           score
           
          1
           Aaron
           78
           
          2
           Bill
           76
           
          4
           Damon
           90
           
          5
           Ella
           73
           

           


          本文來自CSDN博客,轉(zhuǎn)載請標(biāo)明出處:http://blog.csdn.net/houlinghouling/archive/2009/01/09/3741174.aspx



          posted on 2009-06-17 15:28 魯勝迪 閱讀(180) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2009年6月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(4)

          隨筆分類

          隨筆檔案

          文章分類

          新聞分類

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 长丰县| 海南省| 岑巩县| 新晃| 婺源县| 右玉县| 民权县| 绥宁县| 丰宁| 墨脱县| 镇原县| 呼图壁县| 宜兰市| 乌拉特中旗| 固原市| 昔阳县| 朝阳区| 竹北市| 石泉县| 化州市| 光山县| 新民市| 宾川县| 甘南县| 乌什县| 福泉市| 灯塔市| 增城市| 珲春市| 瓮安县| 山西省| 周宁县| 盐亭县| 盐池县| 北安市| 招远市| 山东省| 普安县| 宣威市| 延安市| 永仁县|