簡體   English   中英

根據另一個表中的數據更新mysql表

[英]Update mysql table based on data from another table

我想用另一個表中的數據更新 mySql 中的一個表。

我有兩個表“模板”和“通知”。 模板表通過名為“event_id”的列鏈接到通知表。

templates   notifications
id           id
event_id     global_id
     

我想根據值 templates.event_id = notification.global_id 使用通知表中的 id 更新模板表 event_id。

我嘗試這樣的事情..但它不能像我想要的那樣工作。

          '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 = ?';

也許是這樣的:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM