110,534
社区成员
发帖
与我相关
我的任务
分享
--> Test Data: @A
declare @A table ([ID] int,[CAPTION] varchar(4),[FID] int)
insert into @A
select 1,'ASDF',0 union all
select 2,'ASDF',1 union all
select 3,'ASDF',1 union all
select 4,'ADFF',1 union all
select 5,'ASDF',2
--> Test Data: @B
declare @B table ([Nid] int,[CONTEN] varchar(4),[ID] int)
insert into @B
select 1,'DDDF',0 union all
select 2,'ASDF',1 union all
select 3,'ASDF',1 union all
select 4,'ASDF',1 union all
select 5,'ASDF',2 union all
select 6,'ASDF',2
--Code
--select * from @A
--select * from @B
declare @aid int--A表的ID
set @aid=2
select b.* from
(
select * from @A where fid=(select fid from @a where id=@aid)
) a
join @B b on a.id=b.id
--Drop
--Result
/*
Nid CONTEN ID
----------- ------ -----------
5 ASDF 2
6 ASDF 2
*/
select *
from A
left join B on A.FID=B.ID
where A.ID=youenterID
select *
from A
left join B on A.FID=B.ID
where A.ID=1