Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql: ON DUPLICATE KEY UPDATE ALL VALUES?

Tags:

mysql

Is there any easy way to update all values after a duplicate key? For example:

INSERT INTO published_books
           SELECT * FROM books
           WHERE book_id = book_id
           ON DUPLICATE KEY UPDATE ?everything?

The table has around 50 columns and updating each would be painful. Any ideas?

like image 714
luqita Avatar asked Jun 29 '12 00:06

luqita


1 Answers

You can use REPLACE INTO for this purpose:

REPLACE INTO published_books SELECT * from books;
like image 152
ThiefMaster Avatar answered Nov 15 '22 08:11

ThiefMaster