MySQL concatenation operator
Solution 1:
||
is the ANSI standard string concatenation operator, supported by most databases (notably not MS SQL Server). MySQL also supports it, but you have to SET sql_mode='PIPES_AS_CONCAT';
or SET sql_mode='ANSI';
first.
Solution 2:
You were using ORACLE type of concatenation. MySQL's Should be
SELECT CONCAT(vend_name, '(', vend_country, ')')
Call the CONCAT()
function and separate your values with commas.
Solution 3:
MySQL CONCAT function is used to concatenate two strings to form a single string. Try out following example:
mysql> SELECT CONCAT('FIRST ', 'SECOND');
+----------------------------+
| CONCAT('FIRST ', 'SECOND') |
+----------------------------+
| FIRST SECOND |
+----------------------------+
1 row in set (0.00 sec)
To understand CONCAT function in more detail consider an employee_tbl table which is having following records:
mysql> SELECT CONCAT(id, name, work_date)
-> FROM employee_tbl;
+-----------------------------+
| CONCAT(id, name, work_date) |
+-----------------------------+
| 1John2007-01-24 |
| 2Ram2007-05-27 |
| 3Jack2007-05-06 |
| 3Jack2007-04-06 |
| 4Jill2007-04-06 |
| 5Zara2007-06-06 |
| 5Zara2007-02-06 |
+-----------------------------+
Solution 4:
Whats good about using concat
is that you can pass different data type columns and concat string representations
SELECT concat('XXX', 10.99, 'YYY', 3, 'ZZZ', now(3)) as a;
Output
a
-----
XXX10.99YYY3ZZZ2018-09-21 15:20:25.106
Solution 5:
Simply you can use CONCAT
keyword to concatenate the Strings..
You can use it like
SELECT CONCAT(vend_name,'',vend_country) FROM vendors ORER BY name;