By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
/* Create a test table with our variables to concatenate. */
CREATE TABLE t1 (s1 varchar(50), s2 varchar(50)) ;
INSERT INTO t1 (s1,s2) VALUES ('Hello','World') ;
/* THIS IS THE WAY IT SHOULD BE DONE! */
SELECT concat(s1, ', ', s2, '!') FROM t1 ;
concat(s1, ', ', s2, '!') |
---|
Hello, World! |
/* This is without PIPES_AS_CONCAT turned on. MySQL doesn't honor these operators yet. */
SELECT s1 || ',' || s2 || '!' FROM t1 ;
s1 || ',' || s2 || '!' |
---|
0 |
/* Now turn the mode on so that MySQL honors pipes as concatenators. */
SET sql_mode = 'PIPES_AS_CONCAT' ;
SELECT s1 || ',' || s2 || '!' FROM t1 ;
s1 || ',' || s2 || '!' |
---|
Hello,World! |