Inserting sequence of values into single column - mysql

I need to add one column to my table, which would look like this:
[1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,...]
ie. sequence 1:5
I tried to use this code:
INSERT INTO table (name_of_new_column)
VALUES (1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2.....)
But what I get is this error message:
Column count doesn't match value count at row 1
How can I solve this?

Correct syntax should be :
INSERT INTO table_name (name_of_new_column)
VALUES (1),(2),(3),(4),(5)...
SqlFiddle

Related

ERROR 1136 (21S01): Column count doesn't match value count but am giving same number of values with same data type

I am inserting the same number of values as of my number of columns with correct data type but still, it is showing, column count does not match.
All the columns are here in this link
INSERT INTO map_city VALUES
-> ('IN',744101,'marine jetty','andaman & nicobar islands','south andaman','portblair',11.6667,92.75,3,132,51,57,5,163,55,2770,4.76534296,2.057761733,5.884476534,61.92561093,8.605560944,763.0978608);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
I have also tried, double quotes but still not working.
Try inserting values into columns with respect to their fields, like
INSERT INTO map_city (country_code, pin_code, place_name, ) VALUES ('IN',744101,'marine jetty');
Please Try NULL value for the insert into the auto increment column (id), I think that will fix it.
OR
INSERT INTO tablename (col1,col2,col3) VALUES ('val1','val2','val3')

MySQL INSERT INTO statement generating "Error Code: 1136. Column count doesn't match value count at row"

I am trying to create a new table from an old table so I can remove some duplicates and implement a composite primary key. I have created the new table from the old one using LIKE, so the columns should be identical.
Why does this not work?
INSERT INTO PricesNEWtest (Global_MarketCap,pkey)
VALUES ((SELECT max(Global_MarketCap), pkey
FROM Prices GROUP BY pkey));
Error generated:
Error Code: 1136. Column count doesn't match value count at row 1
The example above only has two rows so it's more legible, but in reality the tables contain 15 columns, this is the full INSERT INTO statement, which generates the same errror:
INSERT INTO PricesNEWtest (Global_MarketCap,Global_Volume24h,BTC_Dominance,Rank,Name,
Symbol,ChangePerc24h,Price,BTC_Price,MarketCap,Volume24h,DateTime,Date,pkDummy,pkey)
VALUES ((SELECT max(Global_MarketCap), max(Global_Volume24h), max(BTC_Dominance), max(Rank), max(Name),
max(Symbol), max(ChangePerc24h), max(Price), max(BTC_Price), max(MarketCap), max(Volume24h),
max(DateTime), max(Date), max(pkDummy), pkey
FROM Prices GROUP BY pkey));
I added the double brackets for VALUES because without it I get error code 1064, but I don't fully understand why the double brackets are necessary. I am grouping by the pkey field (which currently has some duplicates I want to delete), which means I need to summarize the rest of the fields. The SELECT statement works fine on its own as you can see from the screenshot.
Is there another way to do this that I could try? Or is there an easier way to remove the duplicates directly from the original table?
I am using MySQL 5.7.14
Any help would be appreciated!
You just have the wrong syntax to INSERT with a SELECT statement:
INSERT INTO PricesNEWtest (Global_MarketCap, pkey)
SELECT max(Global_MarketCap), pkey
FROM Prices
GROUP BY pkey

MySQL Error Code

I'm trying to insert a data into mysql however, I am receiving an error code which says "Column Count doesn't match value count at row 1" May I know whats the issue with my code below? Thank you.
insert into Student(Studentno,studentFName,StudentLName,DateOfBirth,YearEnrolled,YearGraduated)
Values
(123,'JungKook','Jeon','M','1September1997',2015,2018);
You're supplying more values in the VALUES part of your query than fields in the INSERT INTO Student part.
It looks like 'M' is a value the field for which you have not included a field name between StudentLName and DateOfBirth.
You have more values a s column names in your SQL. You have a value fr gender in the list of values, but no column.
insert into Student(Studentno,studentFName,StudentLName,Gender, DateOfBirth,YearEnrolled,YearGraduated) Values (123,'JungKook','Jeon','M','1September1997',2015,2018);

MySQL column with duplicate values

I have a string column which has duplicate values, for example
row 1 column "desc" has value -> "stack-overflow stack-overflow"
I want to update the column to "stack-overflow"
any idea how to build a query for that?
duplicate record must be symmetric and should be repeated twice only then following will do the trick
select
left
(
'stack-overflow stack-overflow',
length('stack-overflow stack-overflow')/2
)

Insert concatenated values of two colums in a table into a single column of another table

I have a table that has three columns. They are of type VarChar. I am looking to concatenate the values on first and second column and insert that into the First column of another table.
I used this code
insert into table2(cloumn1)
select city+''+Coalesce(zipcode) from table1
I get an error
Error Code: 1292. Truncated incorrect DOUBLE value: 'london'
"London" is the value of the first row and the second row has values like "123.2.4.4"
Both columns are declared as VarChar.
What should I change in the query to get values in the table2 that look like "london 123.2.4.4" ??
You should use the CONCAT() function to concatenate the strings:
insert into table2(cloumn1)
select CONCAT(city, Coalesce(zipcode, ''))
from table1
And be sure that the datatype of the column you are inserting into is a varchar. If the datatype is a double, then you will receive this error.