--关于连接的简单示例--测试数据
declare @a table(ida int)
insert @a select 1
union all select 2declare @b table(idb int)
insert @b select 2
union all select 3--内连接
select * from @a a join @b b on a.ida=b.idb/*--测试结果
只返回两个表中ida与idb相同的记录
ida         idb         
----------- ----------- 
2           2(所影响的行数为 1 行)
--*/
--左连接
select * from @a a left join @b b on a.ida=b.idb/*--测试结果
返回@a(左边表)所有的记录,及@b的idb与@a的ida对应的记录
没有对应的就用null表示ida         idb         
----------- ----------- 
1           NULL
2           2(所影响的行数为 2 行)
--*/
--右连接
select * from @a a right join @b b on a.ida=b.idb/*--测试结果
返回@b(右边表)所有的记录,及@b的idb与@a的ida对应的记录
没有对应的就用null表示ida         idb         
----------- ----------- 
2           2
NULL        3(所影响的行数为 2 行)
--*/
--全连接
select * from @a a full join @b b on a.ida=b.idb/*--测试结果
返回@a与@b的所有记录,没有对应的用NULL表示ida         idb         
----------- ----------- 
2           2
NULL        3
1           NULL(所影响的行数为 3 行)
--*/

解决方案 »

  1.   

    邹建,楼主说的是 loop join
      

  2.   

    什么Loop  Join是什么意思﹖應該是left join吧﹖如果是left join﹐那就是左連的意思﹐左表全部的﹐加上右表符合條件的﹐右表不符合條件的用null來填﹗
      

  3.   

    to : lsxaa(小李铅笔刀) Loop  Join我沒有見過﹐我見過的有left join,right join ,inner join,full join,cross join不知道樓主從哪里看到loop join?
      

  4.   

    哦,那我看错了sql Server中没有发现loop join
      

  5.   

    我測試了﹐用loop join發生語句錯誤
      

  6.   

    楼主到oracle 版去问一下吧?
      

  7.   

    The nested loops join, also called nested iteration, uses one join input as the outer input table (shown as the top input in the graphical execution plan) and one as the inner (bottom) input table. The outer loop consumes the outer input table row by row. The inner loop, executed for each outer row, searches for matching rows in the inner input table. In the simplest case, the search scans an entire table or index; this is called a naive nested loops join. If the search exploits an index, it is called an index nested loops join. If the index is built as part of the query plan (and destroyed upon completion of the query), it is called a temporary index nested loops join. All these variants are considered by the query optimizer. A nested loops join is particularly effective if the outer input is quite small and the inner input is preindexed and quite large. In many small transactions, such as those affecting only a small set of rows, index nested loops joins are far superior to both merge joins and hash joins. In large queries, however, nested loops joins are often not the optimal choice.
      

  8.   


    在ORACLE中:
    连接有三种类型
    散列连接 
    合并连接 
    嵌套循环连接。 
    当在一个程序段中执行到要执行连接时,会显示下列其中一个语句: 
       Hash Join
    或 
       Merge Join
    或 
       Nested Loop Join
    nested loop join 一般适和大小表,且大表有index,全表scan小表,然后按index抽取大表匹配记录,返会第一条记录快。merger join 要对两表排序,然后匹配,要等所有记录处理完后,才能返回结果。hash join 要对一表计算hash值,然后对另一表联接自段算hash,找到匹配记录。
    -----详细内容发到ORACLE版块中去
      

  9.   

    学到东西了,知道oracle里有个nested loop join ...
    一般适和大小表,且大表有index,全表scan小表,然后按index抽取大表匹配记录,返会第一条记录快。
      

  10.   

    hglhyy(查無此人) 所言之oracle的三种联接方式,同样适用于sql server楼主所提的loop join实际上是
    inner loop joininner 可以省略,代表默认的内联接
    loop 是sql server的连接提示, 表明使用 嵌套循环联接(nested loop join)相关内容可以查询帮助 “提示, 联接提示”
      

  11.   

    SQL Server employs three types of join operations: Nested loops joins
    Merge joins
    Hash joins 
    If one join input is quite small (such as fewer than 10 rows) and the other join input is fairly large and indexed on its join columns, index nested loops are the fastest join operation because they require the least I/O and the fewest comparisons. For more information about nested loops, see Understanding Nested Loops Joins. If the two join inputs are not small but are sorted on their join column (for example, if they were obtained by scanning sorted indexes), merge join is the fastest join operation. If both join inputs are large and the two inputs are of similar sizes, merge join with prior sorting and hash join offer similar performance. However, hash join operations are often much faster if the two input sizes differ significantly from each other. For more information, see Understanding Merge Joins. Hash joins can process large, unsorted, nonindexed inputs efficiently. They are useful for intermediate results in complex queries because: Intermediate results are not indexed (unless explicitly saved to disk and then indexed) and often are not produced suitably sorted for the next operation in the query plan.
    Query optimizers estimate only intermediate result sizes. Because estimates can be an order of magnitude wrong in complex queries, algorithms to process intermediate results not only must be efficient but also must degrade gracefully if an intermediate result turns out to be much larger than anticipated. 
    The hash join allows reductions in the use of denormalization to occur. Denormalization is typically used to achieve better performance by reducing join operations, in spite of the dangers of redundancy, such as inconsistent updates. Hash joins reduce the need to denormalize. Hash joins allow vertical partitioning (representing groups of columns from a single table in separate files or indexes) to become a viable option for physical database design. For more information, see Understanding Hash Joins. 
      

  12.   

    { LOOP | MERGE | HASH } JOINSpecifies that all join operations are performed by loop join, merge join, or hash join in the whole query. If more than one join hint is specified, the optimizer selects the least expensive join strategy from the allowed ones. If, in the same query, a join hint is also specified for a specific pair of tables, this join hint takes precedence in the joining of the two tables although the query hints still must be honored. Thus, the join hint for the pair of tables may only restrict the selection of allowed join methods in the query hint. See Hints for details.