首页 > 解决方案 > 如何解决加入问题显示相同的结果

问题描述

我有两张桌子,CustomersListTypeData。我只想加入这两个表。我有CityIdAnd DistrictIdInCustomers表。

它给了我同样CityDistrict如何修复CityAnd 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 ]

标签: c#sql

解决方案


您需要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

推荐阅读