Hopes

          Start Here..

           

          內連接、左外連接、右外連接、全外連接

          --內連接



          select distinct [Order Details] .ProductID,Products.ProductID

          from [Order Details] inner join Products

          on [Order Details] .ProductID=Products.ProductID


          例如:

          SQL語句:select * from student inner join course on student.ID=course.

          IDinner join 是比較運算符,只返回符合條件的行。
          此時相當于:select * from student,course where student.ID=course.ID


          --三個表的內連接
          select Suppliers.CompanyName,Products.ProductName,[Order Details] .ProductID,Products.ProductID

          from Suppliers inner join Products

          on Suppliers.SupplierID=Products.SupplierID

          inner join [Order Details]

          on Products.ProductID=[Order Details].ProductID





          --左外連接
          select Customers.City,Employees.City

          from Customers left join Employees

          on Customers.City=Employees.City

          例如:

               select a.name, a.age, c.sex from b

                left join a on b.id=a.id

                left join c on b.id2=c.id2

                

          又如:

          insert into f as
          select [fields]
          from a
          join b on a.a1=b.b1 and a.a2=b.b2
          join c on c.c1=a.a1 and c.c2=b.b2
          join d on d.d1=b.b1 and d.d3=b.b3
          join e on e.e1=d.d1 and e.e2=a.a4
          where a.a3='3' and b.b3='3' and c.c4='4' and d.d4='4' and e.e3='3';




          --右外連接
          select Customers.City,Employees.City

          from Employees left join Customers

          on Customers.City=Employees.City







          --全外連接
          select Customers.CompanyName,Orders.OrderID,Orders.OrderDate

          from Orders full join Customers

          on Customers.CustomerID=Orders.CustomerID


          內連接:俗稱等同連接,返回的結果集是兩個表中所有相匹配的數據,舍棄不匹配的數據

          SELECT

          FROM <TABLE_1> INNER JOIN <TABLE_2>

          ON <表達式>

          外連接:系統生成的結果表中,不僅包括符合連接條件的行,還包括左表右表或者兩個連接表中所有的數據行

          左外連接:除了包括匹配行之外,還包括join關鍵字左表中不匹配的行,其中右表中缺少的屬性值用NULL值來表示

          右外連接:除了包括匹配行之外,還包括join關鍵字右表中不匹配的行,其中左表中缺少的屬性值用NULL值來表示

          全外連接:除了包括匹配行之外,還包括join關鍵字左右表中不匹配的行,其中左表或者右表缺少的屬性值用NULL 值來表示









          posted on 2012-09-28 14:11 ** 閱讀(179) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          統計

          公告

          你好!

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章分類

          文章檔案

          新聞檔案

          相冊

          收藏夾

          C#學習

          友情鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 碌曲县| 奉节县| 丰镇市| 远安县| 昭通市| 通化市| 谷城县| 山阴县| 修水县| 乐平市| 新丰县| 巫山县| 凉城县| 太仓市| 平度市| 开封县| 舟山市| 鹰潭市| 道真| 三江| 乌苏市| 甘孜县| 固始县| 阿巴嘎旗| 专栏| 巧家县| 锦州市| 顺义区| 成都市| 台南市| 紫金县| 巴林左旗| 平利县| 白山市| 华容县| 中西区| 乐陵市| 金川县| 浪卡子县| 宝坻区| 阿合奇县|