开发者

INSERT INTO SELECT not working

I need help inserting a few selected columns from table1 into another table2 (with a WHERE clause). The columns that I want to insert are the same in both tables. But, each table has other columns that are not in the other table. For example, table2 has a column called 'neighborhood', which is not in table1. I want to grab nid, ccn, reportdatetime, latitude, longitude, event_type from table1 and put it in table2, and the 'neighborhood' column for this new row should be null.

This is my MySQL:

INSERT INTO table2 
SELECT nid, ccn, reportdatetime, latitude, longitude, event_type 
FRO开发者_如何转开发M table1 
WHERE nid=943662

I'm getting this error:

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

Any suggestions on how to get this to work?


Name the columns you're inserting into:

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

This will cause nulls to be inserted into columns that aren't explicitly named

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜