I tried to use "||" for concatenation:
The query I used:
"SELECT id, name, age, age||id FROM myTable;"
This is the output:
Can anyone tell me why the output is not 201 (in first column) and 162(in second column)?? Also it gives similar outputs when I use two attributes that are of varchar datatype and the above two attributes are of int datatype.
3
Answers
There is no such concatenation in mySQL. This is Oracle SQL dialect. You have to use the CONCAT function in mysql
Can anyone tell me why the output is not 201
its because, in mysql, you need to enable
PIPES_AS_CONCAT
. in order to work with||
You can set it using phpmyadmin->variables->searchFor SQL_MODE
Refer mysql doc
But i would suggest you to use
visit the Mysql Documentations :
on this link you will find a list of String Functions and Operators
but you not use|| to concatenate caratcters or strings but do this :
SELECT id, name, age, concat(age,id) FROM myTable;
orSELECT id, name, age, concat_ws(' ',age,id) FROM myTable;
if you want to space the age with id like this for example 23 1. 23 for age and 1 for id.