<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    石建 | Fat Mind

    sql連接查詢

    請參考:http://en.wikipedia.org/wiki/Join_(SQL)#Sample_tables

    inner JOINS

      An inner join is the most common join operation used in applications and can be regarded as the default join-type. Inner join creates a new result table by combining column values of two tables (A and B) based upon the join-predicate. The query compares each row of A with each row of B to find all pairs of rows which satisfy the join-predicate. When the join-predicate is satisfied, column values for each matched pair of rows of A and B are combined into a result row. The result of the join can be defined as the outcome of first taking the Cartesian product (or cross-join) of all records in the tables (combining every record in table A with every record in table B)—then return all records which satisfy the join predicate. Actual SQL implementations normally use other approaches like a Hash join or a Sort-merge join where possible, since computing the Cartesian product is very inefficient.

      注意:innner查詢(默認的連接查詢方式),是先查詢“Cartesian”生成中間表,再根據where條件篩選結果;但此方法非常低效,SQL具體的實現可能是 
    Hash join or a Sort-merge join 。
            
    One can further classify inner joins as equi-joins, as natural joins, or as cross-joins.

    SELECT *
    FROM employee INNER JOIN department
    ON employee.DepartmentID = department.DepartmentID;
    The following example shows a query which is equivalent to the one from the previous example.
    
    
    SELECT *
    FROM   employee, department
    WHERE  employee.DepartmentID = department.DepartmentID;
    

    Outer joins

      An outer join does not require each record in the two joined tables to have a matching record. The joined table retains each record—even if no other matching record exists. Outer joins subdivide further into left outer joins, right outer joins, and full outer joins, depending on which table(s) one retains the rows from (left, right, or both).

    Example of a left outer join, with the additional result row italicized:

    SELECT *
    FROM   employee  LEFT OUTER JOIN department
    ON employee.DepartmentID = department.DepartmentID;
    
    Employee.LastNameEmployee.DepartmentIDDepartment.DepartmentNameDepartment.DepartmentID
    Jones 33 Engineering 33
    Rafferty 31 Sales 31
    Robinson 34 Clerical 34
    Smith 34 Clerical 34
    John NULL NULL NULL
    Steinberg 33 Engineering 33


    Example right outer join, with the additional result row italicized:

    SELECT *
    FROM   employee RIGHT OUTER JOIN department
    ON employee.DepartmentID = department.DepartmentID;
    
    Employee.LastNameEmployee.DepartmentIDDepartment.DepartmentNameDepartment.DepartmentID
    Smith 34 Clerical 34
    Jones 33 Engineering 33
    Robinson 34 Clerical 34
    Steinberg 33 Engineering 33
    Rafferty 31 Sales 31
    NULL NULL Marketing 35


    Example full outer join: (mysql is not support)

    SELECT *
    FROM   employee
    FULL OUTER JOIN department
    ON employee.DepartmentID = department.DepartmentID;
    
    Employee.LastNameEmployee.DepartmentIDDepartment.DepartmentNameDepartment.DepartmentID
    Smith 34 Clerical 34
    Jones 33 Engineering 33
    Robinson 34 Clerical 34
    John NULL NULL NULL
    Steinberg 33 Engineering 33
    Rafferty 31 Sales 31
    NULL NULL Marketing 35


    Self-join

    A query to find all pairings of two employees in the same country is desired.

    An example solution query could be as follows:

    SELECT F.EmployeeID, F.LastName, S.EmployeeID, S.LastName, F.Country
    FROM Employee F, Employee S
    WHERE F.Country = S.Country
    AND F.EmployeeID < S.EmployeeID
    ORDER BY F.EmployeeID, S.EmployeeID;
    

    Which results in the following table being generated.

    Employee Table after Self-join by Country
    EmployeeIDLastNameEmployeeIDLastNameCountry
    123 Rafferty 124 Jones Australia
    123 Rafferty 145 Steinberg Australia
    124 Jones 145 Steinberg Australia
    305 Smith 306 John Germany










    Join algorithms

    Three fundamental algorithms exist for performing a join operation: Nested loop joinSort-merge join and Hash join.




     

    posted on 2010-11-03 15:36 石建 | Fat Mind 閱讀(288) 評論(0)  編輯  收藏 所屬分類: database


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


    網站導航:
     

    導航

    <2010年11月>
    31123456
    78910111213
    14151617181920
    21222324252627
    2829301234
    567891011

    統計

    常用鏈接

    留言簿

    隨筆分類

    隨筆檔案

    搜索

    最新評論

    What 、How、Why,從細節中尋找不斷的成長點
    主站蜘蛛池模板: 大地影院MV在线观看视频免费| 亚洲av高清在线观看一区二区| 2022中文字字幕久亚洲| 亚洲日本视频在线观看| a级成人毛片免费图片| 亚洲Aⅴ无码一区二区二三区软件| 亚洲熟妇无码一区二区三区导航| 成人午夜影视全部免费看| EEUSS影院WWW在线观看免费| 天天影视色香欲综合免费| 在线观看免费a∨网站| 亚洲乱亚洲乱妇无码麻豆| 亚洲一卡2卡三卡4卡无卡下载| fc2成年免费共享视频18| 国产大片91精品免费看3| 四虎国产成人永久精品免费 | 国产大片线上免费观看| 青柠影视在线观看免费| 色屁屁www影院免费观看视频 | 黄网址在线永久免费观看| 亚洲免费一级视频| 无码成A毛片免费| 国产在线精品免费aaa片| 一区二区在线视频免费观看| 久久无码av亚洲精品色午夜 | 成人毛片免费播放| 免费精品人在线二线三线区别| 91九色视频无限观看免费| 久久久精品2019免费观看| 久久免费观看国产99精品| 人妻在线日韩免费视频| 免费看少妇高潮成人片| 国产永久免费高清在线| 国产精品免费大片| 日韩精品久久久久久免费| 最近高清中文字幕免费| 亚洲日本在线免费观看| 国产成人yy免费视频| 国拍在线精品视频免费观看| 免费无码又爽又刺激聊天APP| 久久不见久久见中文字幕免费 |