SQL SERVER,一张表中,有多个字段关联另一张表,怎么写SQL语句?

2024-11-18 08:48:35
推荐回答(3个)
回答1:

对于这个问题,无论语句怎么写,其实执行起来数据库内部还是要用join操作来进行处理的,所以你用join就可以,优化的话可以再User表的id属性上加索引(如果是主键默认是有索引的)

回答2:

原理的确是你那个思路。但可以通过下面方式来简化写法

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

回答3:

join也可以的