table AID   1    
2
3
4
5table B
ID   NAME2    AA
4    BB
5    CC
------------------------------------
如何得到这样的结果
ID  NAME
1   
2   AA
3   
4   BB
5   CC请各位支个招???谢谢~!

解决方案 »

  1.   

    select a.id,
           b.name
    from ta a left join tb b
    on a.id=b.id
      

  2.   

    if not object_id('ta') is null
    drop table ta
    Go
    Create table ta([ID] int)
    Insert ta
    select 1 union all
    select 2 union all
    select 3 union all
    select 4 union all
    select 5
    Go
    if not object_id('tb') is null
    drop table tb
    Go
    Create table tb([ID] int,[NAME] nvarchar(2))
    Insert tb
    select 2,N'AA' union all
    select 4,N'BB' union all
    select 5,N'CC'
    Go
    select a.id,
           isnull(b.name,'')[name]
    from ta a left join tb b
    on a.id=b.id
    /*
    id          name
    ----------- ----
    1           
    2           AA
    3           
    4           BB
    5           CC(5 row(s) affected)*/