Update with select concatenated between two columns of the same mysql table

1

I am trying to execute a query in which I will concatenate two columns of mysql name and surname , and perform the update of this concatenation in the variable full name in all records of the table.

Follow the code:

UPDATE eskalera.curriculum
SET 
nomecompleto = (

SELECT CONCAT(nome, ' ', sobrenome) 

from eskalera.curriculum
) 
    
asked by anonymous 30.04.2016 / 02:45

1 answer

1

The usual way is to use UPDATE:

UPDATE eskalera.curriculum SET nomecompleto = CONCAT(nome,' ',sobrenome);

So this query will be able to make the change in all records of the table in a single transaction. But for this you need to be protected against unwanted updates across the disabled table:

SET SQL_SAFE_UPDATES=0; 

Then we would have:

SET SQL_SAFE_UPDATES=0; 
UPDATE eskalera.curriculum SET nomecompleto = CONCAT(nome,' ',sobrenome);

When finished, it would be interesting to re-enable protection:

SET SQL_SAFE_UPDATES=1; 

So protection against unwanted updates at one time across the table is re-enabled.

    
30.04.2016 / 03:12