I need to copy a full row in an SQL table but add “-Copy” to the end of the MarketName for the copied row. I have the following:
$CopyMarket = "INSERT INTO Markets (MarketName, Size)
(SELECT MarketName, Size)
FROM Markets
WHERE MarketID=$CopyID";
How do I append “-Copy” to the MarketName?
ie: The name is “Colorado,” I want to copy it and insert as a new row as “Colorado-Copy”
Thanks.
Use CONCAT function from MySQL to append or prepend data. Also work in standard SQL.
Append
Prepend
From MySQL documentation :
Returns the string that results from concatenating the arguments. May have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent binary string form; if you want to avoid that, you can use an explicit type cast, as in this example:
CONCAT() returns NULL if any argument is NULL.
For quoted strings, concatenation can be performed by placing the strings next to each other: