select * from a表 as a Full Outer Join b表 as b on a.id=b.id

解决方案 »

  1.   

    最好加一个人员总列表,以便对应人员ID,将ID与人员表对应后
    就可以是向你想要的结果
      

  2.   

    Select a.*,b.book From a表 as a Full Outer Join b表 as b on a.id=b.id
      

  3.   

    select c.[id],c.[name],a.sex,b.book from dbo.c表 as c
    full outer join a表 as a
    on c.id=a.id
    Full Outer Join b表 as b
    on c.id=b.id c表为人员表
      

  4.   

    c表
    id       name
    1        a
    2        b
    3        c
    4        d
    5        e
      

  5.   

    select a.id as id,a.name as name,a.sex as sex,a.book as boook
    from a表 as a left Outer Join b表 as b on a.id=b.id
    union
    select b.id as id,b.name as name,null as sex,b.book as boook
    from a表 as a right Outer Join b表 as b on a.id<>b.id
      

  6.   

    还是不能用select语句表示出结果来,望大家帮帮忙
      

  7.   

    create table #a(id int,name char(2),sex int)
    go
    insert #a values(1,'a', 1)
    insert #a values(2,'b', 0)
    insert #a values(3,'c', 1)
    insert #a values(4,'d', 0)create table #b(id int, name char(2),book varchar(100))
    insert #b values(1,'a','adsfoaiu')
    insert #b values(2,'b','ofuadsou')
    insert #b values(3,'c','oiuou')
    insert #b values(5,'e','ODUFPOAU')
    go
    /*欲查询出如下结果:
    id name sex book
    1 a 1 adsfoaiu
    2 b 0 ofuadsou
    3 c 1 oiuou
    4 d 0 null
    5 e null ODUFPOAU
    */
    select id,max(name) as name ,max(sex) as sex ,max(book) as book from (
    select a.id as id,a.name as name,a.sex as sex,null as book
    from #a as a left outer Join #b as b on a.id=b.id
    union 
    select   b.id as id,b.name as name,null as sex,b.book as book
    from #a as c right outer Join #b as b on c.id=b.id )as d
    group by id
      

  8.   

    --建表
    create table testM(
      ID    int,
      name  varchar(8),
      sex   varchar(1)
      primary key(ID)
    )
    go
    create table testD(
      ID    int,
      name  varchar(8),
      book  varchar(100)
      primary key(ID)
    )
    go--建资料
    insert into testM values(1,'a','1')
    insert into testM values(2,'b','0')
    insert into testM values(3,'c','1')
    insert into testM values(4,'d','0')insert into testD values(1,'a','adsfoaiu')
    insert into testD values(2,'b','ofuadsou')
    insert into testD values(3,'c','oiuou')
    insert into testD values(5,'e','ODUFPOAU')--我查
    select M1.ID,M1.name,M1.sex,D1.book
    from testM M1
    left join testD D1 on M1.ID=D1.ID
    union all
    select D1.ID,D1.name,M1.sex,D1.book
    from testD D1
    left join testM M1 on M1.ID=D1.ID
      

  9.   

    哦,Sql中的 union all应改为union,正确SQL如下:
    select M1.ID,M1.name,M1.sex,D1.book
    from testM M1
    left join testD D1 on M1.ID=D1.ID
    union
    select D1.ID,D1.name,M1.sex,D1.book
    from testD D1
    left join testM M1 on M1.ID=D1.ID