tags:

views:

173

answers:

3

The following query:

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'
    )
)

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?

+2  A: 

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'
rjmunro
+8  A: 

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.

pmarflee
+2  A: 

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'
dcp