我有这3个数据库表
CityTable (List of Cities)
--------
CityCode
CityName
Advertiser (Profile of Advertisers)
----------
AdvertiserCode
AdvertiserName
CityCode
Ads (Transaction Table)
--------
AdsId
AdsTitle
AdsDesc
CityCode
AdvertiserCode
WHERE
Ads.CityCode is Where the Ads is being offered
Advertiser.CityCode is Address of the Advertiser
使用此查询,我只能获取[Ads
]
SELECT Ads.AdsTitle, Ads.AdsDesc, AdsCity, CityTable.CityName AS AdsCityName
FROM Ads
LEFT JOIN CityTable ON CityTable.CityCode = Ads.CityCode
LEFT JOIN Advertiser ON Advertiser.AdvertiserCode = Ads.AdvertiserCode
但我还需要获得广告商的[CityName]
答案 0 :(得分:0)
试试这个:
SELECT Ads.AdsTitle, Ads.AdsDesc, AdsCity, CityTable.CityName AS AdsCityName, AdvCity.CityName AS AdvertiserCity
FROM Ads
LEFT JOIN CityTable ON CityTable.CityCode = Ads.CityCode
LEFT JOIN Advertiser ON Advertiser.AdvertiserCode = Ads.AdvertiserCode
LEFT JOIN CityTable as AdvCity ON AdvCity.CityCode = Advertiser.CityCode