尝试使用内部联接(MySQL)运行更新查询时出错

时间:2013-12-06 00:28:18

标签: mysql

我尝试在MySQL查询中使用以下代码,但在尝试运行它时会收到错误“操作必须使用可更新的查询”。但是,如果我创建另一个简单的更新查询(没有连接和子查询),它工作正常。在这一点难倒。有什么想法吗?

UPDATE IPad
SET Ipad.[case number] = (
    SELECT ipad_damage_history.[case number]
    FROM IPad
    INNER JOIN ipad_damage_history ON IPad.[Apple ID] = ipad_damage_history.[Apple ID]
    WHERE IPad.[case number] IS NULL
      AND IPad.[Apple ID] = ipad_damage_history.[Apple ID]
    )
WHERE Ipad.[Apple ID] = (
    SELECT ipad_damage_history.[Apple ID]
    FROM IPad
    INNER JOIN ipad_damage_history ON IPad.[Apple ID] = ipad_damage_history.[Apple ID]
    WHERE IPad.[case number] IS NULL
      AND IPad.[Apple ID] = ipad_damage_history.[Apple ID]
    );

1 个答案:

答案 0 :(得分:1)

标识符周围的[]是SQL SERVER的东西。在mysql中,您应该在多字列或保留关键字周围使用`

mysql update允许您直接进行内部联接:

UPDATE IPad
INNER JOIN ipad_damage_history 
    ON IPad.`Apple ID` = ipad_damage_history.`Apple ID`
SET Ipad.`case number` = ipad_damage_history.`case number`
WHERE IPad.`case number` IS NULL
      AND IPad.`Apple ID` = ipad_damage_history.`Apple ID`