开发者

SQL: Column count doesn't match row count

The following query:

INSERT INTO term_node( nid, vid, tid )
VALUES (
    (
     SELECT ctb.nid, ctb.vid, 35
     FROM content_type_bout AS ctb
     WHER开发者_JAVA技巧E field_school_value_c = 'Lafayette'
    )
)

Is producing this error:

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

term_node has only three columns in it. What am I doing wrong?


The following should work:

INSERT INTO term_node( nid, vid, tid )
 SELECT ctb.nid, ctb.vid, 35
 FROM content_type_bout AS ctb
 WHERE field_school_value_c = 'Lafayette'

You only use the VALUES clause when you are inserting a single row of data.


You don't say which SQL engine you are using, but my hunch is that you are using too many brackets, so it is grouping the 3 columns in to an array and wanting to post them into one column.

Try:

INSERT INTO term_node( nid, vid, tid )
VALUES (
     SELECT ctb.nid, ctb.vid, 35
     FROM content_type_bout AS ctb
     WHERE field_school_value_c = 'Lafayette'
)

Or even Just:

INSERT INTO term_node( nid, vid, tid )
     SELECT ctb.nid, ctb.vid, 35
     FROM content_type_bout AS ctb
     WHERE field_school_value_c = 'Lafayette'


Try this:

INSERT INTO term_node( nid, vid, tid )
     SELECT ctb.nid, ctb.vid, 35
     FROM content_type_bout AS ctb
     WHERE field_school_value_c = 'Lafayette'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜