4

I am trying to put this into the database. All rows are correct. Each row is also String/Text, except for "Id" which is an auto-incrementing Int value.

I am getting an unexpected error, however, saying Column count doesn't match value count at row 1. What is wrong with the query?

INSERT INTO  `world2_main`.`Messages` (
`Id` ,
`ToId` ,
`FromId` ,
`Subject` ,
`Message` ,
`Read` ,
`Original Sender` ,
`Date`
)
VALUES (
NULL,  '3611',  '156',  'You are so...',  'Cool.',  '0',  '3611'  '1338590308');

4 Answers 4

10

well Id is an autoincrementing int value, and you put a null in it.

Just do

INSERT INTO  `world2_main`.`Messages` (
`ToId` ,
`FromId` ,
`Subject` ,
`Message` ,
`Read` ,
`Original Sender` ,
`Date`
)
VALUES (  '3611',  '156',  'You are so...',  'Cool.',  '0',  '3611'  '1338590308');

EDIT :in fact was just a missing comma after 3611. But avoiding inserting id is still good.

INSERT INTO  `world2_main`.`Messages` (
    `ToId` ,
    `FromId` ,
    `Subject` ,
    `Message` ,
    `Read` ,
    `Original Sender` ,
    `Date`
    )
    VALUES (  '3611',  '156',  'You are so...',  'Cool.',  '0',  '3611',  '1338590308');
Sign up to request clarification or add additional context in comments.

2 Comments

Still errors with "Column count doesn't match value count at row 1"
Thanks for seeing that. Small mistake that took me days to even come close to, lol. I just saw the error a few minutes ago. Appreciate it mate.
6

I have also discovered that if you have a trigger on the table you want to insert into and that trigger have another insert statement with un-matching columns and values, it will throw that error "Column count doesn't match value count at row ".

Comments

2

You may have defined different number of parameters and are probably passing a different number of parameters.

You may have:

INSERT INTO `buyers`(`key1`,  `key2` )
VALUES (value1,value2,value3 );

or more number of arguments in INSERT INTO than in the VALUES

1 Comment

this was my issue, the number of parameters must match
2

Keep in mind 3 things:

  1. Number of parameters must match
  2. auto increment should be taken care of
  3. (This was my issue) When inserting multiple attributes

don't do this--

insert into agent(eid, ename, email, phone, score) values(
    (2, 'b', 'b', 5, 3),
    (1, 'a', 'a', 5, 3)
   );

You have to do this instead

insert into agent(eid, ename, email, phone, score) values
    -> (1, 'a', 'a', 5, 3),
    -> (2, 'b', 'b', 5, 3);

Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.