insert into...select using the same table

This is a discussion on insert into...select using the same table within the MySQL Database forums, part of the Database Forums category; How can I do the following in MySQL. insert into table1 (col1, col2, col3) select col1, col2, somevalue as col3 ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-22-2006
Don Vaillancourt
 
Posts: n/a
Default insert into...select using the same table

How can I do the following in MySQL.

insert into table1 (col1, col2, col3)
select col1, col2, somevalue as col3
from table1

MySQL doesn't allow you to select from the same table you are inserting
into.

Thank You
Reply With Quote
  #2 (permalink)  
Old 03-22-2006
Bill Karwin
 
Posts: n/a
Default Re: insert into...select using the same table

"Don Vaillancourt" <donv@webimpact.com> wrote in message
news:VBjUf.15449$43.2817@nnrp.ca.mci.com!nnrp1.uun et.ca...
> How can I do the following in MySQL.
>
> insert into table1 (col1, col2, col3)
> select col1, col2, somevalue as col3
> from table1


One way would be to store the result of the select in a temporary table, and
then copy that back to table1.

Regards,
Bill K.


Reply With Quote
  #3 (permalink)  
Old 03-22-2006
Don Vaillancourt
 
Posts: n/a
Default Re: insert into...select using the same table

Ok, did some research and got the answer.

It does work on 4.0.14 and higher.



Don Vaillancourt wrote:
> How can I do the following in MySQL.
>
> insert into table1 (col1, col2, col3)
> select col1, col2, somevalue as col3
> from table1
>
> MySQL doesn't allow you to select from the same table you are inserting
> into.
>
> Thank You

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:58 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0