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#學習

          友情鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 彰化县| 连平县| 仙居县| 黑龙江省| 遂昌县| 永胜县| 临夏县| 高安市| 乐昌市| 商水县| 苏尼特右旗| 西盟| 晋州市| 兰西县| 榆社县| 天祝| 吐鲁番市| 五大连池市| 海门市| 大埔区| 巴青县| 句容市| 沁水县| 九龙县| 新泰市| 平罗县| 含山县| 会理县| 松阳县| 梁平县| 苏尼特左旗| 芦山县| 怀仁县| 南汇区| 肇源县| 桐城市| 平阳县| 根河市| 任丘市| 望都县| 卓资县|