Forum Moderators: coopster

Message Too Old, No Replies

MySQL: insert...select - update?

         

erikcw

12:28 am on Apr 29, 2005 (gmt 0)

10+ Year Member



Hi all,

I was reading about insert select
[dev.mysql.com...]

Thought this may be a better way to perform a query I'm doing. The differenc is that I need td select from one field, and then update another field in the same record (it is a backup/undo field).

Is there a way to do this in one query? It's a large chunk of data (longtext) so I thought this would be faster than the alternative...

Tahnks!
Erik

coopster

12:43 am on May 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If you are using MySQL >= 4.1 you could use a subquery. Something aloing the lines of ...
INSERT INTO table 
(column1, column2, column3)
VALUES (
'value1',
'value2',
(SELECT
foreign_value
FROM foreign_table
WHERE key = '$mykey')
)
)
;