I am using MySQL and MySQL Workbench 5.2 CE. When I try to concatenate 2 columns, last_name
and first_name
, it doesn't work :
select first_name + last_name as "Name" from test.student
This question is related to
mysql
mysql-workbench
concat
Use concat() function instead of +
like this:
select concat(firstname, lastname) as "Name" from test.student
That's not the way to concat in MYSQL. Use the CONCAT function Have a look here: http://dev.mysql.com/doc/refman/4.1/en/string-functions.html#function_concat
Try:
select concat(first_name,last_name) as "Name" from test.student
or, better:
select concat(first_name," ",last_name) as "Name" from test.student
MySQL is different from most DBMSs use of +
or ||
for concatenation. It uses the CONCAT
function:
SELECT CONCAT(first_name, " ", last_name) AS Name FROM test.student
As @eggyal pointed out in comments, you can enable string concatenation with the ||
operator in MySQL by setting the PIPES_AS_CONCAT
SQL mode.
Source: Stackoverflow.com