将表 1 与表 2 连接起来,表 2 在每个原始数据中都有两个外键列

时间:2021-06-01 17:16:23

标签: sql-server database

我有两个表,如下所示 -

enter image description here

enter image description here

我想编写一个 SQL 查询(SQL 服务器数据库)来获取结果表格式的数据。 请帮助我编写遵循最佳实践规则的 SQL 查询。 enter image description here

1 个答案:

答案 0 :(得分:2)

加入table2两次

SELECT  Pincode,t2.Lcationname,t3.Lcationname
FROM Table1 t1 
INNER JOIN Table2 t2 ON t1.SourceLocation_id = t2.LocationId
INNER JOIN Table2 t3 ON t1.DestLocation_id = t3.LocationId
相关问题