Monday, May 09, 2005

MySQL, Insert Select

Been working with a PHP function on how can i duplicate an entry. My first approach was to use the while() function, but what it does was loop the entire process.

I posted at phpugph.com and ask them what they think, and they suggested the INSERT - SELECT of MySQL.

mysql> INSERT INTO jt_entry (uid,entry_requested_by,entry_status,entry_category,entry_title,entry_description)
-> select uid, entry_requested_by, entry_status, entry_category, entry_title, entry_description from jt_entry
-> where entry_id='3' limit 1;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
I was not aware about this, and now i know. :)

No comments: