0

I'm uploading multiple entries into a table in our database using MySQL. However, the following command does not work and throws up this error "#1136 - Column count doesn't match value count at row 1"... which is odd as there are 4 columns as included below:

(I've just included two of the results here as an example of the data)

INSERT INTO state (state_id,country_id,state_name,active) VALUES (152,153),(5),(Test1,Test2),(1)

This should form multiple rows and eventually look like this:

state_id | country_id | state_name | active 152 5 Test 1 1 153 5 Test 2 1

(that looks like a table in the edit... but not rendered on here, sorry!)

3
  • 1
    Do you want to insert more than one row? In which column are the two values (152,153) supposed to go? Commented Jan 21, 2012 at 14:03
  • Yes, multiple rows. I should have specified that. So in the end it should look like the edit above Commented Jan 21, 2012 at 14:24
  • See my answer on how to do it. Commented Jan 21, 2012 at 14:26

3 Answers 3

1

To insert multiple rows, you need to supply the correct number of values for each row.

The syntax is such that you specify one row after the other, not columns:

INSERT INTO state 
(state_id,country_id,state_name,active) 
VALUES 
(152,5,'Test1',1), 
(153,5,'Test2',1);
Sign up to request clarification or add additional context in comments.

Comments

1

After VALUES you also have to put groups of 4 values if you defined 4 columns.

Comments

0

Try this:

INSERT INTO state (state_id,country_id,state_name,active) VALUES ('(152,153)','(5)','(Test1,Test2)','(1)')

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.