[英]Update mysql table based on data from another table
I would like to update a table in mySql with data from another table.我想用另一个表中的数据更新 mySql 中的一个表。
I have two tables "templates" and "notifications".我有两个表“模板”和“通知”。 The templates table is linked to the notifications table by a column called "event_id".
模板表通过名为“event_id”的列链接到通知表。
templates notifications
id id
event_id global_id
I would like to update the templates table event_id with the id from the notifications table based on value templates.event_id = notifications.global_id.我想根据值 templates.event_id = notification.global_id 使用通知表中的 id 更新模板表 event_id。
I try something like this.. but it dose not work as I want.我尝试这样的事情..但它不能像我想要的那样工作。
'UPDATE templates
INNER JOIN notifications
ON templates.event_id = notifications.id
SET templates.event_id = notifications.id
WHERE templates.site_id = ? AND notifications.global_id = ?';
Maybe something like this:也许是这样的:
UPDATE templates
JOIN notifications
ON templates.site_id = ? AND notifications.global_id = ?
SET templates.event_id = notifications.id
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.