BEGIN TRANSACTION;
UPDATE `sh_prod_im` SET `updated` = 0;
INSERT
INTO `sh_prod_im` (`article`, ..., `updated`)
VALUES (:article, ..., 1)
ON DUPLICATE KEY UPDATE ..., `updated` = 1;
DELETE FROM `sh_prod_im` WHERE `updated` = 0;
COMMIT;
INSERT
INTO `users_subscriptions` (`user_id`, `subscription_id`)
SELECT IF(`count` < 5, :userId, NULL), :subscriptionId
FROM (
SELECT COUNT(*) AS `count`
FROM `users_subscriptions`
WHERE `user_id` = :userId
) AS `t`