How can we concat
- integers with integers
- varchar with varchar
- int with varchar
in MySQL ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Use CONCAT
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_concat
SELECT CONCAT(1, 2); -- "12" SELECT CONCAT('foo', 'bar'); -- "foobar" SELECT CONCAT(1, 'bar'); -- "1bar"
Method 2
if the arguments include any binary strings, the result is a binary string. A numeric argument is converted to its equivalent binary string form; if you want to avoid that, you can use an explicit type cast, as in this example:
SELECT CONCAT(CAST(int_col AS CHAR), char_col);
Method 3
For two columns concatenation
name: CHAR
and
no: int
PIG syntax is CONCAT(name,(CHARARRAY)no);
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0