lingo5 Posted December 10, 2011 Share Posted December 10, 2011 Hi, I would like to import several columns of a table from database A to database B. Database A has more columns than database B,but they have several columns with the eact same name. I have exported the table from database A as a CSV file. I have tried to import the CSV file to database B, but it imports all the tables and inserts the contents of the non existing tables in db B in the wrong columns. My question is: can I select the columns I want to import from db A and insert their contents in the colums of db B I want? Hope I make sense...thanks. Link to comment https://forums.phpfreaks.com/topic/252876-please-help-importing-columns/ Share on other sites More sharing options...
fenway Posted December 10, 2011 Share Posted December 10, 2011 I have tried to import the CSV file to database B, but it imports all the tables and inserts the contents of the non existing tables in db B in the wrong columns. "it imports"? What's "it"? Link to comment https://forums.phpfreaks.com/topic/252876-please-help-importing-columns/#findComment-1296526 Share on other sites More sharing options...
lingo5 Posted December 10, 2011 Author Share Posted December 10, 2011 sorry I mean when I import the CSV I don't know how to select only the columns i want ...so I end up importing data from db A into the wrong columns of db B... Link to comment https://forums.phpfreaks.com/topic/252876-please-help-importing-columns/#findComment-1296544 Share on other sites More sharing options...
fenway Posted December 10, 2011 Share Posted December 10, 2011 LOAD DATA INFILE let you specify columns. Link to comment https://forums.phpfreaks.com/topic/252876-please-help-importing-columns/#findComment-1296578 Share on other sites More sharing options...
lingo5 Posted December 10, 2011 Author Share Posted December 10, 2011 Thanks fenway..could you please provide an easy to understand for newbie example? Many many thanks Link to comment https://forums.phpfreaks.com/topic/252876-please-help-importing-columns/#findComment-1296585 Share on other sites More sharing options...
The Little Guy Posted December 10, 2011 Share Posted December 10, 2011 if the databases are on the same server and the same user has access to them, you could do this: create table DatabaseB.TableA select * from DatabaseA.TableA Link to comment https://forums.phpfreaks.com/topic/252876-please-help-importing-columns/#findComment-1296595 Share on other sites More sharing options...
lingo5 Posted December 10, 2011 Author Share Posted December 10, 2011 Thanks little guy, but that creates a cop of the table from db A on db B....right? I need to be able to import just some columns from A to B. Link to comment https://forums.phpfreaks.com/topic/252876-please-help-importing-columns/#findComment-1296604 Share on other sites More sharing options...
The Little Guy Posted December 10, 2011 Share Posted December 10, 2011 then list the columns you want in the select like this: create table DatabaseB.TableA select col1, col3, col4, col10 from DatabaseA.TableA Link to comment https://forums.phpfreaks.com/topic/252876-please-help-importing-columns/#findComment-1296626 Share on other sites More sharing options...
lingo5 Posted December 10, 2011 Author Share Posted December 10, 2011 OK, thanks ..I will try this tomorrow because I'm in Spain and it's quite late...gotta go to bed !!! Link to comment https://forums.phpfreaks.com/topic/252876-please-help-importing-columns/#findComment-1296636 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.