Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts
Wednesday, August 7, 2013
SQL Query to Find and Replace Text in MySQL Database
UPDATE TableName set FieldName = replace(FieldName, 'searchFor', 'replaceWith');Wednesday, December 26, 2012
CONCAT in MySQL
CONCAT function returns the string that results from concatenating the arguments.
Example 1:
SELECT CONCAT(column1,column2) from table;
The output for the above will be
Mohanlal
SureshGopi
In between the two columns if you want space or comma, rewrite the query as below
SELECT CONCAT(column1,',',column2) from table;
The output for the above will be
Mohan,lal
Suresh,Gopi
We can also update the table using CONCAT function.
Example 2:
UPDATE table SET column1=CONCAT(column1,column2)
Example 3:
UPDATE table SET column1=CONCAT(column1,'some string')
Example 4: using PHP
mysql_query("UPDATE table SET column1=CONCAT(column1,' ".$variable." ')");
Subscribe to:
Posts (Atom)