Welcome to WebmasterWorld Guest from 50.19.156.19

Forum Moderators: open

Message Too Old, No Replies

Inserting Data - Using INSERT with select

     

humpo

10:12 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



(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

10:59 pm on Sep 21, 2005 (gmt 0)

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



"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

11:49 pm on Sep 21, 2005 (gmt 0)

10+ Year Member



thanks txbakers