Make UPDATE to a MYSQL data via PHP with a similar value from the same query

1

My query in this opportunity is to know if it is possible to make a UPDATE to a database from MySQL where the existing value in the database is only added a letter
My query is as follows:

$query = "UPDATE pedidos SET
    status_pedido = '$status',
    motivo_rechazo = '$motivo',
    fecha_rechazo = '$fecha_act'
    WHERE id = '$id'";

Within the orders table there is a parameter called nro_trans and it is an index or a secondary key and I would like to give an example to the existing data, adding the letter R indicative of rejection.

Existing data = 123456
Updated Data = R123456

I would like to know if there is a way to do it directly in my query or do I have to make a second query to retrieve that data beforehand?

    
asked by Jose M Herrera V 13.11.2018 в 07:02
source

1 answer

3

You should try using the function CONCAT() to indicate to the start the value that you want to add that is the letter R

Then for your requirement it should look like this:

nro_trans = CONCAT('R', nro_trans);
  • Where nro_trans is the same value only that we are going to add the letter R to the beginning
  • First within the CONCAT I add the letter R to concatenate it to the beginning of the value you want to update
  • Here is a link to the official documentation , where you can read that CONCAT accepts from one to more parameters

        
    answered by 13.11.2018 / 07:14
    source