scotchegg78 Posted March 28, 2008 Share Posted March 28, 2008 Hi I have ran a query thats taking forever! Do i need a join for this, Its INSERT INTO new_table (field1,field2,...fieldn) SELECT table_1.id,table_1.name,table_2.company FROM table_1,table_2; So simple I have a tabel I am inserting fields from two tables into. thanks Quote Link to comment https://forums.phpfreaks.com/topic/98309-insert-into-table-from-two-tables-need-a-join/ Share on other sites More sharing options...
scotchegg78 Posted March 28, 2008 Author Share Posted March 28, 2008 Here is the new full code... does this look ok? Could it be better? Insert Into listing_content(listingID,listingName,registeredOwner,registeredManager,RoomNum,registeredCareCategory) SELECT listing.listingID,address.tempHomeName,address.temp_owner,address.temp_regmanager,address.temp_beds,address.temp_regcarecategory FROM listing LEFT JOIN address ON listing.addressID = address.addressID; Quote Link to comment https://forums.phpfreaks.com/topic/98309-insert-into-table-from-two-tables-need-a-join/#findComment-503067 Share on other sites More sharing options...
mwasif Posted March 28, 2008 Share Posted March 28, 2008 Do you have index on listing.addressID and address.addressID? Quote Link to comment https://forums.phpfreaks.com/topic/98309-insert-into-table-from-two-tables-need-a-join/#findComment-503100 Share on other sites More sharing options...
fenway Posted March 28, 2008 Share Posted March 28, 2008 And why the left join? Quote Link to comment https://forums.phpfreaks.com/topic/98309-insert-into-table-from-two-tables-need-a-join/#findComment-503616 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.