insert into select with different column in DUPLICATE KEY UPDATE

INSERT INTO options (owner, name, value, modified)
SELECT owner, name, value, modified, @draft:=draft FROM
(
    ...
) `options`
ON DUPLICATE KEY UPDATE value=VALUES(value), modified=@draft

Above will error with column count doesn’t match row count.

Is there a way I can SELECT a column into @draft without it being included as part of the inserts values but so it’s usable in the DUPLICATE KEY UPDATE?

This entry was posted in Codes & Scripts and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>