MySQL -- Create Table Statement not working

Hi Everyone,

I am trying to create a table in one database based on an existing table in another. Here is the format that I am using:

CREATE TABLE   FirstDatabase.TableToCreate   AS

SELECT * FROM SecondDatabase.SourceTable

It says there is a problem in the syntax, but I cannot find it.

Thanks for any help.
Who is Participating?
Amar BardoliwalaConnect With a Mentor Commented:
Hello johnnypoi,

Apart from permissions, what is the source and destination table names?

Also how are you running the command, from command line or using some software to handle database?

Following is the right syntax

CREATE TABLE db_target.cloned_table 
FROM db_source.source_table;

Open in new window

Hope this will help you.

Thank you.

Amar Bardoliwala.
Obvious questions: does the SourceTable table exists in SecondDatabase? Does the TableToCreate exist in FirstDatabase? Is answer Yes to the second question, add IF NOT EXISTS to the create statement. Read here
Does the user you are logged in with have access to the other database or the rights to create the table in the new database?
What is the error?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.