SELECT TOP (200) B.[Identity], A.Name, A_1.Name AS Expr1
FROM B INNER JOIN
A ON B.Id2 = A.Id INNER JOIN
A AS A_1 ON B.Id1 = A_1.Id
先感谢各位大神帮忙了!
两外键引用同一主键SQL
分享到:
------解决方案-------------------- SELECT * FROM b JOIN A a ON a.Id = b.Id1
JOIN A a2 ON a2.Id = b.Id2
已经差不多了吧 ------解决方案-------------------- try this,
select top (200)
B.[Identity],
(select top 1 a1.Name from A a1 where a1.Id=B.Id2) 'Name',
(select top 1 a2.Name from A a2 where a2.Id=B.Id1) 'Expr1'
from B
------解决方案-------------------- select a.*,b.Name,c.Name as Name1 from A as a inner join B as b on a.id1=b.id inner join B as c on a.id2=c.id ------解决方案-------------------- select * from a,b where a.id=b.id1 or a.id=b.id2 或者
select * from a,b where a.id=b.id1 and a.id=b.id2
具体的要看你的实际需求。 ------解决方案--------------------