如何解决联接问题显示相同的结果

时间:2019-01-04 15:51:33

标签: c# sql

我有两个表,CustomersListTypeData。我只想加入这两个表。 我在CityId表中有DistrictIdCustomers

CityDistrict的修复方法相同 CityDistrict

  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 ]

1 个答案:

答案 0 :(得分:2)

您需要第二次joinListTypesData表:

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