一个主表A,有四个字段,ID, ID1(int),ID2(int),ID3(int);
其中ID1,ID3,使用相同的外键表B(id),来连接的,B有三个字段id(int), name ,code;
那如何来显示表A的ID1,ID3的名称(name)
其中ID1,ID3,使用相同的外键表B(id),来连接的,B有三个字段id(int), name ,code;
那如何来显示表A的ID1,ID3的名称(name)
-->?
select B.id,B.name from B,A where A.ID1=B.id
union all
select B.id,B.name from B,A where A.ID3=B.id
ID1_name=(select top 1 name from B where t.ID1=id),
ID3_name=(select top 1 name from B where t.ID3=id)
from A t
--可以否?
select t.*,
ID1_name=(select top 1 name from B where t.ID1=id),
ID3_name=(select top 1 name from B where t.ID3=id)
from A t