Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INSERT INTO SELECT,copy value+ 'string'

Tags:

sql

mysql

I need to copy a row .
Copied row,I need to change value, this value + 'copy' I made this sql..but it's not work..

INSERT INTO prizes_i18n (
  lang_id
  , translation_name
  , translation_desc
  , name
  , lang_path)
SELECT  prizes_s.lang_id
        , prizes_s.translation_name +  'copy'
        , prizes_s.translation_desc
        , prizes_s.name
        , prizes_s.lang_path   
FROM    prizes_i18n prizes_s 
WHERE   prizes_s.lang_id = 637; 

Without + 'copy' its works. Like this prizes_s.translation_name + 'copyy',but it's not work.

like image 783
Oyeme Avatar asked Sep 16 '10 13:09

Oyeme


People also ask

Can we use insert and select together?

You can use a select-statement within an INSERT statement to insert zero, one, or more rows into a table from the result table of the select-statement. The select-statement embedded in the INSERT statement is no different from the select-statement you use to retrieve data.

What does insert into select statement do?

The INSERT INTO SELECT statement copies data from one table and inserts it into another table. The INSERT INTO SELECT statement requires that the data types in source and target tables match. Note: The existing records in the target table are unaffected.

What is the difference between insert into to select?

INSERT INTO SELECT statement in SQL Server is used to copy data from the source table and insert it into the destination table. The SELECT INTO statement in SQL Server is used to copy data from one (source) table to a new table. INSERT INTO SELECT requires the destination table to be pre-defined.


1 Answers

From this previous question you use MySQL? If so use concat for string concatenation.

SELECT 'foo' + 'bar' ...

Returns 0 in MySQL which would explain the error about doubles you are seeing.

INSERT INTO  prizes_i18n (lang_id, translation_name, translation_desc, 
                          name, lang_path)
SELECT  prizes_s.lang_id,
    concat(prizes_s.translation_name, 'copy'),    
    prizes_s.translation_desc, prizes_s.name, prizes_s.lang_path  
FROM prizes_i18n prizes_s WHERE prizes_s.lang_id = 637;
like image 146
Martin Smith Avatar answered Oct 13 '22 01:10

Martin Smith