Welcome to WebmasterWorld Guest from 54.146.201.80

Forum Moderators: open

Message Too Old, No Replies

Inserting Data - Using INSERT with select

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:58
votes: 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

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

Senior Member

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

joined:Sept 1, 2001
posts:4392
votes: 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.

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:58
votes: 0


thanks txbakers
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members