如果实例尚不存在,我在 MySQL 数据库中有一个表需要更新。我已经尝试了以下方法,但离解决方案还差得远:
SET @last_message_id = (
SELECT id FROM mailbox_last_message WHERE conversationId = '13'
);
BEGIN TRANSACTION;
UPDATE mailbox_last_message SET conversationId = '13', initiatorMessageId = '20', interlocutorMessageId = '10'
WHERE id = @last_message_id
IF (@@ROWCOUNT = 0)
INSERT INTO mailbox_last_message ( id , conversationId , initiatorMessageId , interlocutorMessageId )
VALUES ('' , '13', '20', '0' );
COMMIT;
和这个:
SET @last_message_id = (
SELECT `id` FROM mailbox_last_message WHERE `conversationId` = 13);
INSERT INTO mailbox_last_message ( id , conversationId , initiatorMessageId , interlocutorMessageId )
VALUES ( '', '13', '20', '0' ) ON DUPLICATE
KEY UPDATE id = @last_message_id
此解决方案创建了一个带有 conversationId 13 的新实例,这不是我想要的。我尝试在线搜索文档和各种教程/示例,但找不到任何合适的解决方案。任何帮助将不胜感激。