parsing cols in query

Hello Experts,

Is there a away to write a query in mySQL to parse multiple cols into a single string  col?

like "SELECT (col1 + col2 + col3) aliasName from tbl"

Thank you
Zac
LVL 1
saculAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
VoteyDiscipleConnect With a Mentor Commented:
Actually in MySQL the + operator will try to add the strings and come up with zero.

SELECT CONCAT(col1, col2, col3, 'literals can go in here too') AS aliasName FROM tbl;

... will do the concatenation.
0
 
snoyes_jwCommented:
That's it. Good practice suggests you always use the optional AS keyword to avoid confusion:
SELECT (col1 + col2 + col3) AS aliasName FROM tbl
0
 
saculAuthor Commented:
Perfect,

Thank you for the quick answer.
I guess the + sign is trying to do an addition of the strings over a concatenation.

Thank you,
Zac
0
All Courses

From novice to tech pro — start learning today.