wonderer Posted May 28, 2006 Share Posted May 28, 2006 hello all :)i'm quite newbie so please don't kick me if this question can look stupid :Pi am needing to populate a table copying datas from other tablesi try to explain :)i have tables A, B, C C is emptystructure of table A iscall_id, name, birthday, phone, messagestructure of table B isname_id, nametable C should bename_id, call_id, messageso i have to take 3 fields from table A substituting one of them (name) with corrispondant name_id form table Bi tried like this [code]$q = "SELECT B.name_id FROM B , A WHERE B.name = A.name";$query="INSERT INTO C (name_id, call_id, message) SELECT $q, call_id, message FROM A ORDER by call_id";[/code]obviously it doesn't work [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] any idea of how to make it work?thanks :) Link to comment https://forums.phpfreaks.com/topic/10665-partially-merge-2-tables/ Share on other sites More sharing options...
fenway Posted May 29, 2006 Share Posted May 29, 2006 Sounds like you want the following (UNTESTED):[code]INSERT INTO C (name_id, call_id, message) SELECT B.name_id, A.call_id, A.message FROM A JOIN B ON ( B.name = A.name )[/code] Link to comment https://forums.phpfreaks.com/topic/10665-partially-merge-2-tables/#findComment-39835 Share on other sites More sharing options...
wonderer Posted May 29, 2006 Author Share Posted May 29, 2006 [!--quoteo(post=377962:date=May 29 2006, 03:24 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 29 2006, 03:24 AM) [snapback]377962[/snapback][/div][div class=\'quotemain\'][!--quotec--]Sounds like you want the following (UNTESTED):[code]INSERT INTO C (name_id, call_id, message) SELECT B.name_id, A.call_id, A.message FROM A JOIN B ON ( B.name = A.name )[/code][/quote]thanks i'm gonna try and let u know :) Link to comment https://forums.phpfreaks.com/topic/10665-partially-merge-2-tables/#findComment-39866 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.