如果存在,则在MySQL中重复行

时间:2014-03-02 11:37:18

标签: mysql syntax copy exists duplicate-data

在MSSQL中它正在运行;

IF EXISTS (SELECT id FROM T1 WHERE id=X) 
    BEGIN INSERT INTO T1(C1, C2, C3) 
       (SELECT C1, C2, 'Different Value' AS C3 FROM T1 WHERE id=X) 
    END

MYSQL的对应语法是什么。

提前谢谢

1 个答案:

答案 0 :(得分:1)

只需:

INSERT INTO T1(C1, C2, C3) 
SELECT C1, C2, 'Different Value' AS C3 
FROM T1 
WHERE id=X

如果记录id = X存在,则将插入,否则不插入。