Question

In MSSQL it was working;

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

What is the counterpart syntax for MYSQL.

Thank you in advance

Was it helpful?

Solution

Just:

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

If a record id=X exists, it will be inserted, otherwise not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top