1

I am building a new booking system in PHP at the moment and I want to take over most of the data of the old system (MySQL) however the database structure of the new system will be slightly different. However I think I could take over some of the tables. Is it possible to import rows of old tables to the new table given that the column names are equal but some column names in the new table might be missing?

an example, the old table: tourguides id name address email telephone_mobile telephone_home

the new table tourguides id name address telephone_mobile

the new table doesn't has the column telephone_home, this shouldnt stop the import but instead it should be ignored

2
  • If you are importing through a sql file or csv file then it will give you error but if you try INSERT INTO new_tourguides (id,name,address,telephone_mobile) SELECT id, name, address, telephone_mobile FROM old_touguides then you shouldn't have any probems. Commented Sep 10, 2014 at 12:59
  • Thanks very much Think Different and thiago, thats it. All the best Commented Sep 10, 2014 at 13:13

1 Answer 1

1

Yes, it's possible.

You should do an INSERT SELECT with fixed fields, like this:

INSERT INTO table1 (fieldX, fieldY) SELECT fieldX, fieldY FROM table2

You can even do it between databases:

INSERT INTO db1.table1 (fieldX, fieldY) SELECT fieldX, fieldY FROM  db2.table2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.