Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :

  • id
  • username
  • password
  • email
  • created
  • last_updated
like image 768
Ashish Subedi Avatar asked Sep 16 '25 03:09

Ashish Subedi


1 Answers

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);
like image 195
Madhur Bhaiya Avatar answered Sep 17 '25 18:09

Madhur Bhaiya