Resolve the error Column count doesn’t match value count in MySQL?


This type of error occurs when number of columns does not match whenever you are inserting records in the destination table. For a demo example, let us create a table

mysql> create table errorDemo
   -> (
   -> User_Id int NOT NULL AUTO_INCREMENT,
   -> User_Name varchar(20),
   -> PRIMARY KEY(User_Id)
   -> );
Query OK, 0 rows affected (0.47 sec)

The error is as follows

mysql> insert into errorDemo values('John');
ERROR 1136 (21S01): Column count doesn't match value count at row 1

To avoid this type of error, you need to use the following syntax

insert into yourTableName(yourColumnName1,yourColumnName2,...N)values(yourValue1,yourValue2,....N);

Insert some records in the table using insert command.

The query is as follows

mysql> insert into errorDemo(User_Name) values('John');
Query OK, 1 row affected (0.12 sec)
mysql> insert into errorDemo(User_Name) values('Carol');
Query OK, 1 row affected (0.14 sec)
mysql> insert into errorDemo(User_Name) values('Sam');
Query OK, 1 row affected (0.15 sec)

Display all records from the table using select statement.

The query is as follows

mysql> select *from errorDemo;

The following is the output

+---------+-----------+
| User_Id | User_Name |
+---------+-----------+
| 1       | John      |
| 2       | Carol     |
| 3       | Sam       |
+---------+-----------+
3 rows in set (0.00 sec)

Updated on: 30-Jul-2019

566 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements