Monday, November 21, 2011
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." ')");
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:
Post Comments (Atom)
No comments:
Post a Comment