1

我需要帮助将 table1 中的一些选定列插入另一个 table2(使用 WHERE 子句)。我要插入的列在两个表中是相同的。但是,每个表都有其他表中没有的列。例如,table2 有一个名为“neighborhood”的列,它不在 table1 中。我想从table1中获取nid、ccn、reportdatetime、latitude、longitude、event_type并放到table2中,这个新行的'neighborhood'列应该为null。

这是我的 MySQL:

INSERT INTO table2 
SELECT nid, ccn, reportdatetime, latitude, longitude, event_type 
FROM table1 
WHERE nid=943662

我收到此错误:

#1136 - Column count doesn't match value count at row 1

关于如何让它工作的任何建议?

4

1 回答 1

15

命名您要插入的列:

INSERT INTO table2 (nid, ccn, reportdatetime, latitude, longitude, event_type) 
SELECT nid, ccn, reportdatetime, latitude, longitude, event_type 
FROM table1 
WHERE nid=943662;

这将导致空值被插入到未明确命名的列中

于 2011-09-09T23:58:47.680 回答