有如下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
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
left join table2 B
on A.[ID]=B.[ID]
where A.基本信息='AAA'
select t1.TD,t1.基本信息,t2.id as 2id,t2.参数
from table1 t1 left join table2 t2 on t2.id=t1.ID
where t1.基本信息=‘AAA’
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'
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'