我有两个表,Customers
和ListTypeData
。我只想加入这两个表。
我在CityId
表中有DistrictId
和Customers
。
City
和District
的修复方法相同
City
和District
。
SELECT c.[CustomerId]
,c.[Name]
,c.[CompanyName]
,c.[ShopNo]
,list.[Description] AS 'City'
,list.[Description] AS 'District'
FROM [MakkiRuskFaisalabad].[dbo].[Customers] c
JOIN [dbo].[ListTypesData] list ON c.CityId = list.ListTypeDataId ]
答案 0 :(得分:2)
您需要第二次join
到ListTypesData
表:
SELECT c.CustomerId
,c.Name
,c.CompanyName
,c.ShopNo
,list.Description AS 'City'
,list2.Description AS 'District'
FROM MakkiRuskFaisalabad.dbo.Customers c
JOIN dbo.ListTypesData list ON c.CityId = list.ListTypeDataId
JOIN dbo.ListTypesData list2 ON c.DistrictId = list2.ListTypeDataId