David Gard
David Gard

Reputation: 12047

MySQL reporting unknow column on a column that was not specified

I'm trying to insert values in to a table but I'm hitting an error that I cannot overcome -

INSERT INTO dd_poll_options (option_text, option_order, poll_id) VALUES (a, 0, 6),(b, 1, 6),(c, 2, 6),(d, 3, 6),(e, 4, 6),(f, 5, 6);

The error being generated as below. As you can see from the code sample, 'a' is a value, not a column name -

Unknown column 'a' in 'field list'

I've checked the MySQL 'INSERT' doc's which seem to suggest the code is sound, with the give example -

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

I've tried wrapping the column names in backtricks (`), but the same error is generaged.

Can someone please help me find why this error is occuring, and how to fix it? Thanks.

Upvotes: 0

Views: 27

Answers (1)

juergen d
juergen d

Reputation: 204854

You need quotes around strings like a

INSERT INTO dd_poll_options (option_text, option_order, poll_id) 
VALUES ('a', 0, 6),
       ('b', 1, 6),
       ('c', 2, 6),
       ('d', 3, 6),
       ('e', 4, 6),
       ('f', 5, 6);

Otherwise the DB engine would look for a column with that name.

Upvotes: 2

Related Questions