homepage Welcome to WebmasterWorld Guest from 54.237.98.229
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Inserting Data - Using INSERT with select
humpo

10+ Year Member



 
Msg#: 48 posted 10:12 pm on Sep 21, 2005 (gmt 0)

(using mysql)

Trying to insert records into a new table but also insert a value which does not exist in the old table

This simple example works fine, but i canít see how i could insert values which donít come from the oldTable
INSERT INTO newTable (field1,field3,field4)
SELECT field1, field3, field4
FROM oldTable;

newTable has an extra field called newID which i would like to populate at the same time.
Something like this:
INSERT INTO newTable (field1,field3,field4, $newID)
SELECT field1, field3, field4
FROM oldTable;

Any ideas?

Thanks

 

txbakers

WebmasterWorld Senior Member txbakers us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 48 posted 10:59 pm on Sep 21, 2005 (gmt 0)

"INSERT into table1 (f1,f2,f3,f4) SELECT f1,f2,f3," & $newID & " FROM table2 WHERE......."

you need to break the SQL string into parts to include the variable like you want to.

humpo

10+ Year Member



 
Msg#: 48 posted 11:49 pm on Sep 21, 2005 (gmt 0)

thanks txbakers

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved