I want to execute this MySQL query:
INSERT INTO `cron-stats` (`user`) VALUES (".(int)$d['by-user'].")
Whenever such user doesn’t exist yet, as in:
SELECT 1
FROM `cron-stats`
WHERE `user` = ".(int)$d['by-user']."
How can I execute this in one query?
you can use
ON DUPLICATE KEY UPDATEbut in order to perform the
INSERTstatement well, you need to set aUNIQUEindex on columnuser.if the column has no
indexyet, execute the statement below,