0

I have a table called pages with the following fields:

  • page_id
  • f_page_object_id
  • deactivation_date
  • deactivation_editor
  • is_published

When I want to deactivate a page, I need the f_page_object_id returned to be able to edit the connected row of a different table too.

I tried using OUTPUT INSERTED, but it does not seem to work (giving syntax error). I was wondering if I am using it right and it is even possible here:

UPDATE `pages` SET deactivation_date = '2016-01-14 16:10:31', deactivation_editor = 'test', is_published = '0' 
OUTPUT INSERTED.f_page_object_id
WHERE page_id = 291;
PIDZB
  • 903
  • 1
  • 15
  • 38
  • MySQL doesn't support `OUTPUT`. You have to `SELECT` the value back out. You could create a stored procedure to wrap both actions. – Michael Berkowski Jan 14 '16 at 19:15
  • Looks like there is a trick used by a few: http://stackoverflow.com/questions/1388025/how-to-get-id-of-the-last-updated-row-in-mysql – JNevill Jan 14 '16 at 19:16
  • @JNevill This does indeed seem to work, but MySQL does not return a value from the bottom SELECT statement from the first example? If I ask for a result, it returns as false? – PIDZB Jan 14 '16 at 22:40
  • @Abayob Are you sure this is mysql question and not mssql one? – Mladen Oršolić May 08 '18 at 11:55

0 Answers0