Thursday, January 8, 2015

[MySQL][SQL] Simple tutorial about CONCAT

According the offical explaination, CONCAT is to returns the string that results from concatenating the arguments.This is a simple example from Microsoft to understand how to use CONCAT and what do it returns:



SELECT CONCAT ( 'Happy ', 'Birthday ', 11, '/', '25' ) AS Result;


As you seen on the image above, CONCAT is to concatenate the strings into a single string.



* **

And now let try an SQL with CONCAT to add some string after the returned result, you can  click here to make the sample table to try this example SQL:
 




SELECT id, post_title, CONCAT( post_title, '- ','new ','text') AS new_post_title
FROM wp_posts
 Result :



Remarks


1) It requires a minimum of two input values
2) Beware that CONCAT() would returns NULL if any argument is NULL:

SELECT CONCAT('My', 'S', 'QL');
SELECT CONCAT(  'My',  null,  'QL' )
 



Reference:
 

No comments :

Post a Comment