0

我想将临时表中的所有字段移动到另一个表中,但我的语句似乎不起作用。在生成要在插入语句中使用的临时表后,如何选择某些字段。

这是我生成临时表的代码,它可以工作:

> CREATE TEMPORARY TABLE table2 AS(SELECT ca.catref AS cx_ref, c.name AS code_name, ca.title, ca.keywords, ca.cat1, ca.cat2, ca.cat3, ca.active, ca.moderated,
FROM table ca
JOIN anothertable c ON c.prefix = LEFT( ca.catref, 3 ))   

这是我之后直接调用的代码,它引用了临时表,但似乎不起作用......

> INSERT INTO mytable (catref, cartoonist, title, keywords, cat1, cat2, cat3, active, moderated, source_db)
SELECT catref, code_name, title, keywords, cat1, cat2, cat3, active, moderated, source_db from table2
4

1 回答 1

1

您在第一个查询(创建临时)中有错误,之后ca.moderate,删除昏迷... ca.moderated,

CREATE TEMPORARY TABLE table2 AS(
SELECT ca.catref AS cx_ref, c.name AS code_name, 
ca.title, ca.keywords, ca.cat1, ca.cat2, ca.cat3,
ca.active, ca.moderated
FROM table ca
JOIN anothertable c ON c.prefix = LEFT( ca.catref, 3 )) 

插入试试这个:

INSERT INTO `mytable` 
(catref, cartoonist, title, keywords, cat1, cat2, cat3, active, moderated, source_db) 
SELECT * 
from `table2` 
于 2013-02-26T18:33:30.757 回答