Domanda

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

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top