0

I want to copy a table from one database to another. Both the tables are on the same server but in different databases. I can see the both from the phpMyAdmin of the same server. I tried to run the following SQL command:

SELECT * INTO first_db.table_name FROM second_db.table_name

I replace first_db, table_name and second_db with my actual database and table names. Unfortunately, running these queries gives me the following error:

Undeclared variable: first_db

All the database and table names actually exist.

Thanks.

Real Noob
  • 1,369
  • 2
  • 15
  • 29
  • 1
    Does this answer your question? [select into in mysql](https://stackoverflow.com/questions/16809393/select-into-in-mysql) – CodeLikeBeaker Sep 28 '20 at 20:52
  • 1
    Since you're already using phpMyAdmin, is there any reason why you aren't using the "Copy table to (database.name)" dialog in the original table's Operations tab? This seems to be the simple solution to me. – Isaac Bennetch Oct 01 '20 at 15:14
  • Thanks @IsaacBennetch. I missed this option. I have one question. :) What happens if there is already a table and I just want to update the information in that table from the original table? Right now, I just delete the new table and again copy the original table whenever there is an update. – Real Noob Oct 01 '20 at 18:21
  • Unfortunately in this case the copy feature requires that the other table not exist, otherwise you'll get an error message that the table name is already in use. For updating an existing table, you probably need some SQL command. – Isaac Bennetch Oct 29 '20 at 20:14

0 Answers0