dbTalk Databases Forums  

Is it possible to change single column in INSERT - SELECT query?

comp.databases.mysql comp.databases.mysql


Discuss Is it possible to change single column in INSERT - SELECT query? in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
A
 
Posts: n/a

Default Is it possible to change single column in INSERT - SELECT query? - 08-29-2011 , 11:36 AM






I want to do this:

INSERT INTO Table2(column1,column2,column3)
SELECT column1,column2,'somecustomvalue'
FROM Table1 WHERE id IN(1,2,3);

Of course the above query is not proper - what I want is to put a custom
value for column3 but copy the rest from Table1. Is this possible like this
and in a single query?

I am actually looking for this for SQLite but mysql solution will do as
well.

Reply With Quote
  #2  
Old   
A
 
Posts: n/a

Default Re: Is it possible to change single column in INSERT - SELECT query? - 08-29-2011 , 11:37 AM






forgot to mention - both tables have identical structure.

Reply With Quote
  #3  
Old   
anonymous
 
Posts: n/a

Default Re: Is it possible to change single column in INSERT - SELECT query? - 08-29-2011 , 12:28 PM



On 8/29/2011 12:36 PM, A wrote:
Quote:
I want to do this:

INSERT INTO Table2(column1,column2,column3)
SELECT column1,column2,'somecustomvalue'
FROM Table1 WHERE id IN(1,2,3);

Of course the above query is not proper - what I want is to put a custom
value for column3 but copy the rest from Table1. Is this possible like this
and in a single query?

I am actually looking for this for SQLite but mysql solution will do as
well.


What error did you get when you tried to run the query exactly as you
typed it above (I don't see anything wrong with it)?

Reply With Quote
  #4  
Old   
A
 
Posts: n/a

Default Re: Is it possible to change single column in INSERT - SELECT query? - 08-29-2011 , 03:25 PM



Quote:
What error did you get when you tried to run the query exactly as you
typed it above (I don't see anything wrong with it)?
OMG... I gave myself a solution without even trying it... I assumed that
would never work it was too damn obvious.
Yes, you're right, it works and also works in SQLite too.... thanks
anonymous!

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.