(轉貼)數據庫連接(內連接,外連接,交叉連接)

          數據庫連接分為:內連接,外連接(左、右連接,全連接),交叉連接
          文章地址 : http://www.zxbc.cn/html/20080527/51189.html
          轉載 
          內連接:把兩個表中數據對應的數據查出來 
          外連接:以某個表為基礎把對應數據查出來(全連接是以多個表為基礎) 
          student表 
          no name 
          1     a 
          2     b 
          3     c 
          4     d 
          grade表 
          no grade 
          1     90 
          2     98 
          3     95 
          內連接 inner join(查找條件中對應的數據,no4沒有數據不列出來) 
          語法:select * from student inner join grade on student.no = grade.no 
          結果 
          student.no name grade.no grade 
          1             a             1         90 
          2             b             2         98 
          3             c             3         95 
          左連接(左表中所有數據,右表中對應數據) 
          語法:select * from student left join grade on student.no = grade.no 
          結果: 
          student.no name grade.no grade 
          1                 a         1         90 
          2                 b         2         98 
          3                 c         3         95 
          4                 d     
          右連接(右表中所有數據,左表中對應數據) 
          語法:select * from student right join grade on student.no = grade.no 
          結果: 
          student.no name grade.no grade 
          1                 a         1         90 
          2                 b         2         98 
          3                 c         3         95 
          全連接 
          語法:select * from student full join grade on student.no = grade.no 
          結果: 
          no name grade 
          1     a     90 
          2     b     98 
          3     c     95 
          4     d 
          1     a     90 
          2     b     98 
          3     c     95 
          注:access 中不能直接使用full join ,需要使用union all 將左連接和右連接合并后才可以

          交叉連接
          將兩個表所有行組合,連接后的行數為兩個表行數的乘積(笛卡爾積)
          語法,借用上面的例子應該是
          select * from student cross join grade

          行數應該為12行 :
          no name grade 
          1     a     90 
          2     b     98 
          3     c     95 
          4     d  
          1     a     90 
          2     b     98 
          3     c     95 
          4     d 
          1     a     90 
          2     b     98 
          3     c     95 
          4     d 

          posted on 2011-11-30 17:24 AK47 閱讀(499) 評論(0)  編輯  收藏 所屬分類: 數據庫

          <2011年11月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          導航

          統計

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 涟源市| 乌拉特中旗| 宁津县| 吕梁市| 辛集市| 洱源县| 武义县| 军事| 缙云县| 广宁县| 祥云县| 临潭县| 乌拉特中旗| 阜南县| 秭归县| 乐陵市| 临沭县| 阳信县| 金乡县| 镇远县| 西畴县| 屏山县| 瑞昌市| 南汇区| 乐东| 焉耆| 调兵山市| 杭锦旗| 囊谦县| 寻乌县| 兴和县| 景泰县| 巨野县| 阜新| 浦东新区| 万州区| 天祝| 扎赉特旗| 驻马店市| 昌吉市| 大港区|