After executiing query, why it gives table not exist error ?
-
15-06-2021 - |
Question
I am trying to execute following query:
Insert into pligg_links_temp
select *
from pligg_links
WHERE link_id > 0 and link_id < 10000;
but I get this error:
#1146 - Table 'chris123_pligg.pligg_links_temp' doesn't exist when trying to execute query to create table
the table does not exist but it should be created in the process or am I wrong?
Solution
Copying records from a table to another table can be done in two ways.
- insert by selection into an existing table.
- create and insert by selection into a new table, created from selected table fields structure.
Your error stacktrace says that the table pligg_links_temp
doesn't exist.
Then your statement to create and insert
table data is incorrect.
To copy records from an existing table to a new table, you require to use CREATE TABLE ... SELECT Syntax
syntax.
Use the following sample:
create table pligg_links_temp -- as /* as is optional */
select * from pligg_links WHERE link_id > 0 and link_id < 10000;
If the target table already exists, you can use INSERT ... SELECT Syntax
statement to copy records.
insert into pligg_links_temp
select * from pligg_links WHERE link_id > 0 and link_id < 10000;
OTHER TIPS
The query should be
CREATE TABLE pligg_links_temp AS SELECT * FROM pligg_links WHERE link_id > 0 and link_id < 10000;
No, it wouldnt create it for you. http://dev.mysql.com/doc/refman/5.5/en/insert.html clearly says the table must exist.