Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql string concatenation returns 0

im trying to concatenate 3 columns in a select query to show in one column in the results. the column is called DelPostalName and for some reason always shows a '0' when i run the select query. like its trying to add up the strings but theres not actual numbers to add. ive been googling string concatenation and this seems to be the correct syntax. any ideas?

isc_orders.ordShipFirstName + ' ' + isc_orders.ordshiplastname + isc_orders.ordshipcompany as DelPostalName,
like image 263
phil Avatar asked May 31 '11 08:05

phil


1 Answers

The result appears as zero since you are trying to arithmetically add the strings to each other.

The correct method for concatenating strings in MySQL is using the CONCAT(str1, str2, str3) function.

Here is the manual for the function.

PS: if you want to concate with a seperator use CONCAT_WS() - also in the same manual

like image 140
BigFatBaby Avatar answered Sep 19 '22 15:09

BigFatBaby