如何在MYSQL中写“何时匹配更新”

时间:2019-04-02 04:21:26

标签: mysql db2

在DB2中,我可以写

 MERGE INTO    Table1 AS A
       USING (
       SELECT *
   FROM        TABLE2
   WHERE        NO.1 = NO.2) AS B ON
   A.TOKEN_ID = B.TOKEN_ID
   WHEN MATCHED THEN UPDATE
   SET        A.LINK_POSTING_IND = 1;

但是MYSQL不支持MERGE,那么如何在MYSQL中重新编写此代码?

1 个答案:

答案 0 :(得分:0)

您可以使用更新联接在MySQL中重新定义合并语句:

UPDATE Table1 A
INNER JOIN
(
    SELECT TOKEN_ID
    FROM TABLE2
    WHERE NO.1 = NO.2
) B
    ON A.TOKEN_ID = B.TOKEN_ID
SET
    LINK_POSTING_IND = 1;