我有一个'mytable'表,它有以下结构和样本数据。
+----+------------+--------------------+
| id | name | password |
+----+------------+--------------------+
| 1 | Raj | somepwd |
+----+------------+--------------------+
| 2 | Rao | abcdefg |
+----+------------+--------------------+
| 3 | Uday | |
+----+------------+--------------------+
我想用Rao的密码更新Uday的密码。 任何人都可以帮我解决MySQL的更新问题。
提前致谢。
答案 0 :(得分:0)
UPDATE mytable
set
password=(SELECT password FROM mytable WHERE name LIKE 'Rao')
WHERE name LIKE 'Uday'
答案 1 :(得分:0)
您需要使用此查询。
update mytable as t1,
(select id,`password` from mytable where name = 'Rao') as t2
set t1.password = t2.password
where t1.id = 3
答案 2 :(得分:0)
update mytable set password = (select password from mytable where id=2) where id=3
或者您可以使用自我加入
update mytable t1 join mytable t2 on t1.id = 3 set t1.password = t2.password
where t2.id=2
注意:使用id而不是其他列
答案 3 :(得分:0)
我得到了解决方案,实际上,所有解决方案都给我错误。
UPDATE mytable as aa, (SELECT password FROM mytable where id =2) as bb SET aa.password=bb.password where aa.id=3;