Aamir Mukaram
Aamir Mukaram

Reputation: 49

If exists in mysql not working

    IF EXISTS (SELECT * FROM pages WHERE pages.id = 21)
UPDATE `pages` SET `content`='Updated' WHERE (`id`='21')
ELSE
INSERT INTO `pages` (`subject_id`) VALUES ('102')

Not Working What is the problem

Upvotes: 1

Views: 225

Answers (1)

echo_Me
echo_Me

Reputation: 37243

try this

 INSERT INTO `pages` (`subject_id`) VALUES ('102')
 ON DUPLICATE KEY UPDATE `content`='Updated' 
 WHERE `id`='21'

Upvotes: 1

Related Questions