1
    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

echo_Me
  • 37,078
  • 5
  • 58
  • 78
Aamir Mukaram
  • 49
  • 1
  • 9
  • Is it inside function? If not then you can't use `IF EXISTS` as control structure, see http://stackoverflow.com/questions/5528854/usage-of-mysqls-if-exists – Andrey Jul 17 '13 at 13:29

1 Answers1

1

try this

 INSERT INTO `pages` (`subject_id`) VALUES ('102')
 ON DUPLICATE KEY UPDATE `content`='Updated' 
 WHERE `id`='21'
echo_Me
  • 37,078
  • 5
  • 58
  • 78
  • Agree with the idea assuming id is a unique field, but put id in the field list of the insert , and put the id value of 21 into the values. – Kickstart Jul 17 '13 at 13:32