34,588
社区成员
发帖
与我相关
我的任务
分享
--测试数据
if not object_id(N'Tempdb..#T1') is null
drop table #T1
Go
Create table #T1([id] int,[A] int)
Insert #T1
select 1,10 union all
select 2,20 union all
select 3,30
GO
if not object_id(N'Tempdb..#T2') is null
drop table #T2
Go
Create table #T2([id] int,[B] int)
Insert #T2
select 1,100 union all
select 2,200
Go
--测试数据结束
SELECT id ,
a ,
( SELECT b
FROM #t2
WHERE #t2.id = #t1.id
)
FROM #t1