SQL SERVER,一张表中,有多个字段关联另一张表,怎么写SQL语句?
例如A表中有aUserid,bUserid,cUserid字段,但显示的时候我肯定是不想显示id的,得join一下User表来取得UserName,我知道可以join三次...
例如A表中有aUserid,bUserid,cUserid字段,但显示的时候我肯定是不想显示id的,得join一下User表来取得UserName,我知道可以join三次User表,但有没有更简单效率的办法?难道一定要N个字段关联User表我就要join它N次?
展开
展开全部
原理的确是你那个思路。但可以通过下面方式来简化写法
select
auserid,auserdes = (select userdes from user b where a.auserid = b.user),
buserid,buserdes = (select userdes from user b where a.bauserid = b.user),
cuserid,cuserdes = (select userdes from user b where a.causerid = b.user),
from userlist a
select
auserid,auserdes = (select userdes from user b where a.auserid = b.user),
buserid,buserdes = (select userdes from user b where a.bauserid = b.user),
cuserid,cuserdes = (select userdes from user b where a.causerid = b.user),
from userlist a
来自:求助得到的回答
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询