能否用一个SQL语句从A表中根据各登录ID字段,取B表中对应的用户名显示出来?
如果A表仅有一个字段,直接Inner join B表就行了,但是A表有多个ID字段,都对应B表,所以请教!
如果先把A、B表下载成CURSOR,再用程序替换,是可以,但是不是一个SQL语句。
3 个解决方案
#1
select b.name,c.name,d.name,...
from a
join b on a.id1=b.id
join b as c on a.id2=c.id
join b as d on a.id3=d.id
......
from a
join b on a.id1=b.id
join b as c on a.id2=c.id
join b as d on a.id3=d.id
......
#2
select * from a
join
(select distinct 登录ID,用户姓名 from tb)b
on a.登录ID=b.登录ID
#3
看错了,应该是这个。
#1
select b.name,c.name,d.name,...
from a
join b on a.id1=b.id
join b as c on a.id2=c.id
join b as d on a.id3=d.id
......
from a
join b on a.id1=b.id
join b as c on a.id2=c.id
join b as d on a.id3=d.id
......
#2
select * from a
join
(select distinct 登录ID,用户姓名 from tb)b
on a.登录ID=b.登录ID
#3
看错了,应该是这个。