<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查詢(默認(rèn)的連接查詢方式),是先查詢“Cartesian”生成中間表,再根據(jù)where條件篩選結(jié)果;但此方法非常低效,SQL具體的實(shí)現(xiàn)可能是 
    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 閱讀(297) 評論(0)  編輯  收藏 所屬分類: database


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


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

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

    統(tǒng)計(jì)

    常用鏈接

    留言簿

    隨筆分類

    隨筆檔案

    搜索

    最新評論

    What 、How、Why,從細(xì)節(jié)中尋找不斷的成長點(diǎn)
    主站蜘蛛池模板: 国产亚洲美女精品久久久久| 你懂的免费在线观看网站| 中文字幕中韩乱码亚洲大片 | 精品一区二区三区免费观看| 亚洲精品亚洲人成在线观看| 色se01短视频永久免费| 特级毛片在线大全免费播放| 亚洲精品免费在线观看| 日本一道一区二区免费看| baoyu116.永久免费视频| 亚洲中文字幕久久精品无码2021 | 无码乱人伦一区二区亚洲一| 成人午夜性A级毛片免费| 永久免费av无码网站yy| 亚洲日本一线产区和二线 | 1000部夫妻午夜免费| 特级无码毛片免费视频| 久久精品国产亚洲av高清漫画| 免费国产真实迷j在线观看| 亚洲一区二区在线免费观看| 色婷婷精品免费视频| 亚洲一区二区久久| 亚洲AV永久无码精品| 免费一级毛片在播放视频| 国产成人精品免费视频大| 久久久久国色AV免费观看| 欧洲 亚洲 国产图片综合| 精品国产亚洲一区二区三区| 国产国产成年年人免费看片| 一色屋成人免费精品网站| 18禁超污无遮挡无码免费网站| 婷婷国产偷v国产偷v亚洲| 亚洲一区在线观看视频| 亚洲国产精品国自产拍电影| 亚洲国产精品成人AV无码久久综合影院 | www.亚洲色图.com| 免费无码又黄又爽又刺激| 免费视频精品一区二区三区| 人妻免费久久久久久久了| 亚洲国产区男人本色| 亚洲国产精品综合久久久|