CBG Posted April 8, 2011 Share Posted April 8, 2011 Hi, I would like to do the following in PHP using a MySQL database, but not sure how. select a, b,c etc.. from mailbox where id = X then insert id,a,b,c etc.. into problem When I select, I will be calling the id So I would like it to get data from mailbox and then insert it into problem. How would I go about doing this? Thanks for any help you can give me Link to comment https://forums.phpfreaks.com/topic/233057-select-then-insert-into-another-table/ Share on other sites More sharing options...
Lyleyboy Posted April 8, 2011 Share Posted April 8, 2011 Try having a read about subqueries or derived tables as they are sometimes know. Something like this should work INSERT INTO tblTABLE SET (Field1, Field2) VALUES (SELECT Field1, Field2 FROM tblTABLE2) It's a very simplified example but the logic should work. Link to comment https://forums.phpfreaks.com/topic/233057-select-then-insert-into-another-table/#findComment-1198691 Share on other sites More sharing options...
CBG Posted April 8, 2011 Author Share Posted April 8, 2011 Thanks for the reply I will give that code ago and if it doesn't work do a google on subqueries and/or derived tables. Thanks again Link to comment https://forums.phpfreaks.com/topic/233057-select-then-insert-into-another-table/#findComment-1198722 Share on other sites More sharing options...
CBG Posted April 8, 2011 Author Share Posted April 8, 2011 Just thought I would come back with a follow up on this. It working fine. I didn't put SET in it, as I thought that was for update. But anyway it works great. Thank you very much Link to comment https://forums.phpfreaks.com/topic/233057-select-then-insert-into-another-table/#findComment-1198895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.