两个表
t1
-------------------
netid name
-------------------
1 mm
2 kk
3 gg
...t2
-----------------------
linkID inWhichNet
-----------------------
L1 3
L2 3
L3 2
L4 1inWhichNet和t1.netid 是同一种内容
现在想查询
linkID,name 怎么操作啊?
t1
-------------------
netid name
-------------------
1 mm
2 kk
3 gg
...t2
-----------------------
linkID inWhichNet
-----------------------
L1 3
L2 3
L3 2
L4 1inWhichNet和t1.netid 是同一种内容
现在想查询
linkID,name 怎么操作啊?
from t2 b
left outer join t1 a
on b.inwhichnet=a.netid
inner join t1
on te2inWhichNet=t1.netid
from t1 ,t2
where t2.inWhichNet=t1.netid
if object_id('t1') is not null drop table t1
create table t1 (netid int,name varchar(2))
insert into t1
select 1,'mm' union all
select 2,'kk' union all
select 3,'gg'
--> 测试数据: t2
if object_id('t2') is not null drop table t2
create table t2 (linkID varchar(2),inWhichNet int)
insert into t2
select 'L1',3 union all
select 'L2',3 union all
select 'L3',2 union all
select 'L4',1
select * from t1
select t2.linkId,t1.name from t1 join t2 on t2.inWhichNet=t1.netid
/*
linkId name
----------- -----------
L1 gg
L2 gg
L3 kk
L4 mm
*/