且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Query使用Sql join和没有子查询来获取结果表

更新时间:2023-02-26 09:54:32

您必须两次加入tblLocation表。这看起来像

You must JOIN the tblLocation table two times. That looks something like
SELECT tblRoute.Id as RouteId, a.Cityname as SourcePlace, b.Cityname as DestinationPlace
FROM tblRoute
INNER JOIN tblCity a ON tblRoute.SourcePlace=a.Id
INNER JOIN tblCity b ON tblRoute.DestinationPlace=b.Id


SELECT a.Id as RouteId, b.Cityname as SourcePlace, c.Cityname as DestinationPlace
from tblRoute a inner join tblLocation b on a.SourcePlace = b.Id
left outer join tblLocation c on a.DestinationPlace = c.Id





在SQL Server上测试 - 2008 R2 ,它工作正常。



Tested it on SQL Server - 2008 R2, It works fine.