2017-10-12 68 views
-1

我想更新我的街道地址,郵政編碼和城市的信息從2表 2表包含它自己的屬性,但他們有相同的街道地址,郵政編碼和城市的信息,現在我想更新2表的信息......我如何編寫更新語句?任何人都可以>>? ..如何更新mysql中的兩個表?

它給我錯誤當我做更新..任何人都可以檢查我嗎?

UPDATE DEPARTMENT a INNER JOIN LOCATION b 
    ON a.street address = b.street address 
AND a.postal_code = b.postal_code, 
AND a.city=b.city, 
AND a.country_name = b.county_name, 
SET street_address = 'subang 1 ,subang jaya ' , 
    postal code = '31546', 
city = 'PETALING JAYA ', 
    country_name = 'MALAYSIA', 
WHERE DEPARTMENT = 'Accounting'; 

回答

0

= b.street address

刪除逗號和引用應當以書面形式在它前面的表的別名更新的列。如果你想更新你有兩個表中相同名稱的字段寫出來的每一列

+0

我刪除它,但它給我靠近集error..syntax錯誤街道地址.. –

+0

我還穿上了一個郵政局,城市,國家名稱= B已經..我仍然得到錯誤 –

+0

斯里,我忽略了一些東西。你一開始只需要一次set命令。 – iLikeMySql

0

嘗試此查詢

UPDATE DEPARTMENT a 
INNER JOIN LOCATION b ON a.street address = b.street address 
AND a.postal_code = b.postal_code 
AND a.city=b.city 
AND a.country_name = b.county_name 
SET a.street_address = 'subang 1 ,subang jaya ', 
    b.street_address = 'subang 1 ,subang jaya ', 
    a.postal_code = '31546', 
    b.postal_code = '31546', 
    a.city = 'PETALING JAYA ', 
    b.city = 'PETALING JAYA ', 
    a.country_name = 'MALAYSIA', 
    b.country_name = 'MALAYSIA', 
WHERE DEPARTMENT = 'Accounting'; 
+0

它說我的附近SET a.street_address ='subang 1,subang jaya',語法錯誤:( –

相關問題