有如下2表:table1:
ID    基本信息
1        sdf
2        wrfwer
3        AAA
4        w34dtable2:
id      参数
1     2004-3-2
2     2006-3-1我想通过联结查询得到如下数据:仅在table1表中出现且基本信息=‘AAA’:的ID查询结果应该如下:
ID      基本信息    id     参数
3         AAA        NULL   NULL

解决方案 »

  1.   

    select A.[ID],A.基本信息,B.[ID],B.[參數] from table1 A
    left join table2 B 
    on A.[ID]=B.[ID]
    where A.基本信息='AAA'
      

  2.   

    select table1.id, table1.基本信息 ,table2.id,table2.参数 from table1 left join table2 on table1.id= table2.id where table1.基本信息=‘AAA’
      

  3.   


    select t1.TD,t1.基本信息,t2.id as 2id,t2.参数
    from table1 t1 left join table2 t2 on t2.id=t1.ID
    where t1.基本信息=‘AAA’
      

  4.   

    select * from table1 a left outer join table2 b on a.id=b.id where a.基本信息='aaa'
      

  5.   


    Declare  @table1 table  (id  int,bast  varchar(9))
    Declare  @table2 table  (id  int,par   varchar(15)  )insert  into    @table1
    Select  1,'sdf'
    union all 
    Select  2, 'wrfwer'
    union all  
    Select  3,'AAA'
    union all
    Select   4,'w34d'insert   into    @table2
    Select  1,'2004-3-2'
    union all
    Select   2,'2006-3-1'Select  *   From  @table1Select  *   From  @table2Select *  
    From   @table2  t2 ,  @table1  t1
    Where  t1.id*= t2.id
    And    bast='AAA'
      

  6.   

    create table t1(
    id int,
    基本信息 varchar(50)
    )
    insert t1 select 1,'sdf' union all
    select 2,'wrfwer' union all
    select 3,'aaa' union all
    select 4,'w34d'create table t2(
    id int,
    参数 datetime null
    )
    insert t2 select 1,'2004-03-02'
    union all select 2,'2006-03-01'select t1.id,t1.基本信息,t2.id,t2.参数
    from t1 left join t2 on t1.id=t2.id
    where t1.基本信息='aaa'