34,590
社区成员
发帖
与我相关
我的任务
分享
select
distinct a.id,a.name,b.user
from
a, b
where
a.id=b.id
select distinct a.id,a.name,b.user
from 表1 a,表2 b where a.id=b.id
declare @表1 table (ID int,NAME varchar(1))
insert into @表1
select 1,'A' union all
select 2,'B' union all
select 3,'C'
declare @表2 table (ID int,[USER] varchar(2))
insert into @表2
select 1,'01' union all
select 1,'02' union all
select 1,'01' union all
select 2,'02' union all
select 2,'03' union all
select 3,'02'
select distinct a.*,b.NAME from @表2 a
left join @表1 b on a.ID=b.ID
/*
ID USER NAME
----------- ---- ----
1 01 A
1 02 A
2 02 B
2 03 B
3 02 C
*/
select distinct tb1.id , tb1.name ,tb2.users
from tb1 left join tb2
on tb1.id =tb2.id
select a.id,a.name,t.user from
(
select distinct * from b
) as t join a on t.id = a.id
select distinct a.id,a.name,b.user
from 表1 a,表2 b where a.id=b.id