mysql错误代码:1093。您无法在FROM子句中为更新指定目标表'S'

时间:2015-11-25 18:16:07

标签: mysql

我知道这个问题有答案,但我无法理解,因为他们的问题代码与我的不一样。 我这里有代码:

UPDATE S 
SET city=(SELECT city FROM S WHERE s_name='Adams')
WHERE s_name='Smith';

我试图根据其他问题的答案修改代码:

UPDATE S 
SET city=(SELECT city FROM (SELECT* FROM S) AS temta WHERE s_name='Adams')
WHERE s_name='Smith';

即使查询成功但我得到空值,该值也不会像我预期的那样更新。

1 个答案:

答案 0 :(得分:0)

你试过这样:

UPDATE S 
SET city=(SELECT city FROM (SELECT * FROM S WHERE s_name='Adams') AS temta )
WHERE s_name='Smith';

OR

UPDATE S 
SET city=(SELECT c FROM (SELECT city as c FROM S WHERE s_name='Adams') AS temta )
WHERE s_name='Smith';

注意:您确定子查询结果只有一行吗?