Ashish Subedi
Ashish Subedi

Reputation: 53

mysql error; Error Code: 1136. Column count doesn't match value count at row 1

I am just learning MySQL and am trying to create a basic table. But I am getting this error:

Error Code: 1136. Column count doesn't match value count at row 1.

Query is

insert into user(username,password,email,created,last_updated) values (
    ('TEST USERNAME','TEST PASSWORD','[email protected]',current_timestamp(),current_timestamp()), 
    ('TEST USERNAME 2','TEST PASSWORD 2','[email protected]',current_timestamp(),current_timestamp())
);

The columns in the table are :

Upvotes: 4

Views: 5403

Answers (2)

user11863576
user11863576

Reputation: 1

your columns in your table has id yet you don't have it when you wrote

insert into user(username,password,email,created,last_updated)

you should write

insert into user(id,username,password,email,created,last_updated)

Upvotes: 0

Madhur Bhaiya
Madhur Bhaiya

Reputation: 28834

Remove the brackets for Values(..), i.e., it should be Values (..), (..) instead.

insert into user(username,password,email,created,last_updated) 
values
('TEST USERNAME','TEST PASSWORD','[email protected]',current_timestamp(),current_timestamp()), 
('TEST USERNAME 2','TEST PASSWORD 2','[email protected]',current_timestamp(),current_timestamp());

From Docs, the syntax is:

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
    [INTO] tbl_name
    [PARTITION (partition_name [, partition_name] ...)]
    [(col_name [, col_name] ...)]
    {VALUES | VALUE} (value_list) [, (value_list)] ...
    [ON DUPLICATE KEY UPDATE assignment_list]

...

INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of comma-separated column values, with lists enclosed within parentheses and separated by commas. Example:

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

Upvotes: 4

Related Questions