56,678
社区成员
发帖
与我相关
我的任务
分享
--测试数据
if not object_id(N'Tempdb..#T1') is null
drop table #T1
Go
Create table #T1([id] int,[msg] nvarchar(23),[uid] int,[uuid] int)
Insert #T1
select 1,N'测试',1,2 union all
select 1,N'测试2',3,1
GO
if not object_id(N'Tempdb..#T2') is null
drop table #T2
Go
Create table #T2([uid] int,[name] nvarchar(22))
Insert #T2
select 1,N'张三' union all
select 2,N'李四' union all
select 3,N'王五'
Go
--测试数据结束
SELECT a.id ,
a.msg ,
b.name ,
c.name
FROM #T1 a
JOIN #T2 b ON b.uid = a.uid
JOIN #T2 c ON a.uuid = c.uid