2013-08-26 112 views
0

這是我走到這一步,但它的錯誤:MySQL的試圖從另一個表列與值替換列的值

UPDATE item_template_epix 
    SET armor = 
     (SELECT armor 
     FROM item_template) 
WHERE entry IN (SELECT entry FROM item_template WHERE armor > 1); 

錯誤:

[Err] 1242 - Subquery returns more than 1 row 
+1

就像錯誤說的那樣,你的子查詢返回多於一行。您可能需要爲每一個「頂部1」,或添加一些其他查詢限制以將它們縮減爲單個行。 – Amy

+2

使用JOIN搜索'sql update'。事實上,你告訴它用許多其他值更新你的表的每個值,這是行不通的。 –

+0

我正在嘗試爲整個列執行此操作,而不僅僅是一行。 –

回答

0

我想你需要這樣的:

UPDATE item_template_epix 
JOIN item_template ON item_template_epix.entry = item_template.entry 
SET item_template_epix.armor = item_template.armor 
WHERE item_template.armor > 1 
+0

[錯誤] 1064 - 您的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以便在第3行的FROM item_template_epix JOIN item_template ON item_template_epix.entry = item_'處使用正確的語法 –

+0

Yeh ...這是SQL服務器語法,您應該指定它是MySQL。 – Magnus

+0

你是對的...對不起。 –

0

你可以試試這個。

 UPDATE item_template_epix SET (armor) = (WITH OneValue AS 
    (SELECT entry FROM item_template Where armor > 1)) 
          SELECT armor FROM OneValue); 
+0

不幸的,但這裏有錯誤:你的SQL語法有錯誤;檢查與你的MySQL服務器版本相對應的手冊,以便在'(armor)=(WITH OneValue AS(選擇護甲) FROM item_template'1'的地方使用正確的語法 –

+0

您可以擴展該方法的工作方式/原因請求者的問題? –

+0

「WITH OneValue AS」是一個Oracle屬性,我剛剛注意到你有Mysql平臺,對這個誤解感到抱歉。 – zee

相關問題