我知道这个问题有答案,但我无法理解,因为他们的问题代码与我的不一样。 我这里有代码:
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';
即使查询成功但我得到空值,该值也不会像我预期的那样更新。
答案 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';
注意:您确定子查询结果只有一行吗?