1

I am trying to create a temporary table and add information from another table into it. However I keep getting the error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT course_name, ins_name FROM courses where course_name='ACCA'' at line 2'

Can somebody tell me what I am doing wrong?

Here is my code:

INSERT INTO #TempTable (course, ins) 
  SELECT course_name, ins_name
  FROM courses
  where course_name = 'ACCA'
1
  • 2
    I believe the syntax is SELECT ... INTO #Table FROM ... Commented May 30, 2016 at 11:16

2 Answers 2

3

You should create the temp table first

 CREATE TEMPORARY TABLE 
 IF NOT EXISTS your_table  AS (SELECT course_name, ins_name
             FROM courses 
             where course_name='ACCA');
Sign up to request clarification or add additional context in comments.

Comments

1

your syntax is fine. However in order to use it you must first create table #TempTable.

More details Here

1 Comment

i think in this case the error will be Table doesn't exist

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.