Search code examples
mysqlsqlsql-insertmysql-select-db

INSERT SELECT with string SQL


i want to copy the content of one column to another column. The copied content should be linked to a string.

|  company  |  new_company  |
_____________________________
Google      | The Google Company

Here the "The" and "Company" are attached as a string to the content.

I have tried a lot, which is the most meaningful to me looks like:

INSERT INTO table_name (copy_into_column)
SELECT CONCAT('The ', copy_from_column, ' Company')
FROM table_name

But with this sql i get that error:

#1292 - Incorrect datetime value: '0000-00-00 00:00:00' for column 'time' at row 1035

Of course, I have several columns in my right table, but actually should be disregarded or?

I hope someone has an idea.


Solution

  • Aren't you looking for update statement?

    UPDATE table_name
    SET copycol = CONCAT('The ', copy_from_column, ' Company')
    

    About the error that you get:

    You have a timestamp field that apparently is required. from the code you've shared, I see that you are inserting new rows into DB, where I guess you don't fill the other columns.