SQL Server Joining one table twice with another table

gjmwrych  于 2023-03-17  发布在  其他
关注(0)|答案(1)|浏览(210)

I have below table A - which has From and To Location.
| From | To |
| ------------ | ------------ |
| ABC | FG |

Below table B - has the Location longitude and latitude

ZipLatLong
ABC9080
FG4567

I want to combine the above two tables to get the below result wherein From Location has latitude and longitude and similarly To Location has Latitude and Longitude.

FromFrom_LatFrom_LongToTo_LatTo_Long
ABC9080FG4567

Can someone help with the syntax to join table A and table B to get the desired results?

v8wbuo2f

v8wbuo2f1#

You'll need to use two join clauses:

SELECT [from], f.lat, f.long, [to], t.lat, t.long
FROM   tab_a a
JOIN   tab_b f ON a.[from] = f.zip
JOIN   tab_b t ON a.[to] = t.zip

相关问题