Frage

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?

War es hilfreich?

Lösung

Copying records from a table to another table can be done in two ways.

  1. insert by selection into an existing table.
  2. 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;

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top