[英]Set value of select statement into variable and use in update query mysql
[英]Set a value of select in update query MYSQL
如何在更新查询中使用选择结果? 例如:
Update access_rights
set rfidcode=(Select rfidcode from users where name like 'thomas')
where id_access_rights=3;
这行不通。 谁能帮我 ?
Update access_rights a, users u
set a.rfidcode = u.rfidcode
where a.userid = u.userid --change this to appropriate join column
and u.name like '%thomas%'
and a.id_access_rights=3;
假设您要更新单个记录,则选择查询需要返回单个结果。 使用limit关键字。
Update access_rights
set rfidcode=(Select rfidcode from users where name like 'thomas' limit 1)
where id_access_rights=3;
vkp解决方案,如果您想更新许多相关记录,但必须注意联接,否则会出错,或者更糟的是破坏数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.