BEGIN
IF EXISTS( SELECT * FROM `table1` WHERE `id` = 1 AND `chat` = 12 LIMIT 1 ) THEN
UPDATE `table1` SET `q` = `q` + 1 WHERE `id` = 1 AND `chat` = 12 LIMIT 1
ELSE
INSERT INTO `table1` ( `id`, `chat`, `q` ) VALUES ( 1, 12, 1 )
END IF;
END
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'IF EXISTS( SELECT * FROM `table1` WHERE `id` = 1 AND `chat` = 12' at line 2
CREATE TABLE `table1` (
`id` int,
`chat` int,
`q` int,
PRIMARY KEY (`id`, `chat`)
);
INSERT INTO `table1` ( `id`, `chat`, `q` )
VALUES ( 1, 12, 1 )
ON DUPLICATE KEY UPDATE `q` = `q` + 1;