简体   繁体   中英

how to concatenate two column values and store in a another column mysql php

I want to insert two column values(Year + ID(Primarykey-AutoIn) = SRF) in to one column

i can able to concatenate the values using the following code SELECT CONCAT(Year, ID) AS SRF FROM billing_details but i dont know how to insert those values in a column namely "SRF".

Updated Question:

Now i have used the following code

$sqlselect = "UPDATE billing_details SET SRF = CONCAT(Year, ID)";

it returns as "Null"

UPDATE billing_details SET SRF = CONCAT(Year, ID)

You first need to add the column to your table, assuming it does not exist yet:

ALTER TABLE billing_details ADD COLUMN srf VARCHAR(100);

And then use an update statement:

UPDATE billing_details 
SET srf = CONCAT(year, id);

The issue has been resolved by using the following code courtesy to Mr.Girish ( Column concatenation returns "Null" Mysql - Php ) and other sweet supporters(Akond, Mureinik, Jens, Valentin Rusk and etc "Thank you all for giving valuable support" )

//Concatenation of Year+ID=SRF
$sqlselect = "UPDATE billing_details SET SRF = CONCAT(`Year`, `ID`)";

if (!mysqli_query($con,$sqlselect)) {
die('Error: ' . mysqli_error($con));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM