Welcome to WebmasterWorld Guest from 54.161.201.189

Forum Moderators: open

Inserting Data - Using INSERT with select

   
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

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.

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

10+ Year Member



thanks txbakers
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month