我有3张桌子
我想将iata_code列从表iata_en复制到d_citites表,其中(iata_en.cityname = d_cities.cityname)和iata_en.countryname = d_cities.country_name)
我写了这段代码,但它不起作用
UPDATE d_cities
SET iata_code=iata_en.iata_code
FROM iata_en,d_cities as ci
INNER JOIN d_country as co
ON ci.CountryID=co.CountryID
WHERE iata_en.city_name=ci.city
AND iata_en.country_name=co.country
答案 0 :(得分:2)
所有表引用都必须在UPDATE
子句中指定,即使您实际上没有更新它们。
UPDATE
d_cities
JOIN d_country USING (CountryID)
JOIN iata_en ON (
city_name = city
AND country_name = country
)
SET
d_cities.iata_code = iata_en.iata_code
答案 1 :(得分:0)
尝试此查询:
UPDATE D_CITIES CITIES
JOIN D_COUNTRY COUNTRY ON COUNTRY.COUNTRY_ID = CITIES.COUNTRY_ID
JOIN IATA_EN IATA ON IATA.CITY_NAME = CITIES.CITY_NAME
SET CITIES.IATA_CODE = IATA.IATA_CODE;