Created
June 11, 2017 19:08
-
-
Save apphp/aa9ae09966b3dac277da70a8e8548fca to your computer and use it in GitHub Desktop.
Insert or Update Record if Unique Key Already Exists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- source: http://www.apphp.com/index.php?snippet=mysql-insert-or-update-if-unique-key-already-exists | |
-- Unique key for table must be pre-defined | |
INSERT INTO `tableName` | |
VALUES (field1,field2,field3,'-1',...,fieldN,'0') | |
ON DUPLICATE KEY | |
UPDATE `field1` = 'abc', `field2` = '123' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment