表A
a
-----
1
2
3
4
表B
b
-----
2
3
4
5
6我想用以个联查查询出a     b
----------
1     null
2     2
3     3
4     4
null  5想了半天实在没想出来
请高手指点指点.......
谢谢了

解决方案 »

  1.   

    select *
    from a full join b on a.a=b.b
      

  2.   

    谢谢 高手指点........请问 full就代表所有列都显示出来吗????
    :)顺便结贴.....
      

  3.   

    ----------------------------------------------------------------
    -- Author  :fredrickhu(我是小F,向高手学习)
    -- Date    :2009-12-09 16:05:27
    -- Version:
    --      Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) 
    -- Nov 24 2008 13:01:59 
    -- Copyright (c) 1988-2005 Microsoft Corporation
    -- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
    --
    ----------------------------------------------------------------
    --> 测试数据:[a]
    if object_id('[a]') is not null drop table [a]
    go 
    create table [a]([a] int)
    insert [a]
    select 1 union all
    select 2 union all
    select 3 union all
    select 4
    --> 测试数据:[b]
    if object_id('[b]') is not null drop table [b]
    go 
    create table [b]([b] int)
    insert [b]
    select 2 union all
    select 3 union all
    select 4 union all
    select 5 union all
    select 6
    --------------开始查询--------------------------
    select a.a,b.b from a full join b on a.a=b.b
    ----------------结果----------------------------
    /* a           b
    ----------- -----------
    1           NULL
    2           2
    3           3
    4           4
    NULL        5
    NULL        6(6 行受影响)
    */
      

  4.   

    你可以这么理解
    FULL JOIN=LEFT JOIN+RIGHT JOIN
      

  5.   

    declare @A table (a int)
    insert into @A select 1 
        union all  select 2
        union all  select 3
        union all  select 4
    declare @B table (b int)
    insert into @B select 2
         union all select 3
         union all select 4
         union all select 5
         union all select 6
    select top 5 * from @A a full join 
                  @B b on a.a=b.b/*
    (4 行受影响)(5 行受影响)
    a           b
    ----------- -----------
    1           NULL
    2           2
    3           3
    4           4
    NULL        5(5 行受影响)*/